有人知道如何确定用户在DataGrid
控件中点击的位置?
我正在使用.NET CF和Windows Mobile 6.我需要知道的是用户是单击所选单元格还是空白区域(未被列或行覆盖)。有没有办法从EventArgs
检索它?
感谢。
答案 0 :(得分:2)
这是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);
}