开发者

C# datagrid click position

开发者 https://www.devze.com 2022-12-24 18:46 出处:网络
D开发者_如何学Gooes anybody know how can I determine where the user clicked in a DataGrid control ?

D开发者_如何学Gooes anybody know how can I determine where the user clicked in a DataGrid control ? I'm using .NET CF with Windows Mobile 6. What I need to know is whether the user clicked on the selected cell or on an empty area (not covered by columns or rows). Is there a way to retrieve it from EventArgs ?

Thanks.


This is from MSDN

private void myDataGrid_MouseDown(object sender, 
System.Windows.Forms.MouseEventArgs e)
{
   DataGrid myGrid = (DataGrid) sender;
   System.Windows.Forms.DataGrid.HitTestInfo hti;
   hti = myGrid.HitTest(e.X, e.Y);
   string message = "You clicked ";

   switch (hti.Type) 
   {
      case System.Windows.Forms.DataGrid.HitTestType.None :
         message += "the background.";
         break;
      case System.Windows.Forms.DataGrid.HitTestType.Cell :
         message += "cell at row " + hti.Row + ", col " + hti.Column;
         break;
      case System.Windows.Forms.DataGrid.HitTestType.ColumnHeader :
         message += "the column header for column " + hti.Column;
         break;
      case System.Windows.Forms.DataGrid.HitTestType.RowHeader :
         message += "the row header for row " + hti.Row;
         break;
      case System.Windows.Forms.DataGrid.HitTestType.ColumnResize :
         message += "the column resizer for column " + hti.Column;
         break;
      case System.Windows.Forms.DataGrid.HitTestType.RowResize :
         message += "the row resizer for row " + hti.Row;
         break;
      case System.Windows.Forms.DataGrid.HitTestType.Caption :
         message += "the caption";
         break;
      case System.Windows.Forms.DataGrid.HitTestType.ParentRows :
         message += "the parent row";
         break;
      }

      Console.WriteLine(message);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消