我想在datagrid 里面 实现如下简单功能。
点击某cell的时候 选中 该cell所在的行,并且foucs还在该cell上。可是当我 把选中代码如下:
System.Windows.Forms.DataGrid.HitTestInfo hti;
hti = this.dataGrid1.HitTest(e.X, e.Y);
row = hti.Row;
this.dataGrid1.Select(hti.Row);
我把这些代码放到 dataGrid1_MouseDown 事件中 ,发现不能选中(事实上是先被选中了,后又被取取消了 )
放到dataGrid1_Mouseup事件 中 发现 可以选中。
由此, 我推断 这两个事件之间 可能还发生了别的事件。那么我想问问 ,在我单击 datagri的 的一个cell 的时候 都发生了哪些事件?
特别是 dataGrid1_MouseDown 和dataGrid1_Mouseup之间发生了哪些事件?
点击某cell的时候 选中 该cell所在的行,并且foucs还在该cell上。可是当我 把选中代码如下:
System.Windows.Forms.DataGrid.HitTestInfo hti;
hti = this.dataGrid1.HitTest(e.X, e.Y);
row = hti.Row;
this.dataGrid1.Select(hti.Row);
我把这些代码放到 dataGrid1_MouseDown 事件中 ,发现不能选中(事实上是先被选中了,后又被取取消了 )
放到dataGrid1_Mouseup事件 中 发现 可以选中。
由此, 我推断 这两个事件之间 可能还发生了别的事件。那么我想问问 ,在我单击 datagri的 的一个cell 的时候 都发生了哪些事件?
特别是 dataGrid1_MouseDown 和dataGrid1_Mouseup之间发生了哪些事件?
就可以了.
public static void select_grid_mouseUp(System.Windows.Forms.MouseEventArgs e,System.Windows.Forms.DataGrid gridname) //DataGrid点击选定行....
{
System.Windows.Forms.DataGrid.HitTestInfo info = gridname.HitTest(e.X, e.Y);
if (info.Type == System.Windows.Forms.DataGrid.HitTestType.Cell)
{
gridname.Select(info.Row);
}
}
public static void select_grid_mouseDown(System.Windows.Forms.MouseEventArgs e,System.Windows.Forms.DataGrid gridname) //DataGrid点击选定行....
{ System.Windows.Forms.DataGrid.HitTestInfo info = gridname.HitTest(e.X, e.Y);
if(e.Button == System.Windows.Forms.MouseButtons.Right)
{
if(info.Row>=0)
{
gridname.UnSelect(gridname.CurrentRowIndex);
gridname.CurrentRowIndex=info.Row;
gridname.Select(info.Row);
}
} }