开发者

C# datagrid click position

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜