如何实现选择DataGrid单元格时显示选择一行

首先创建一个用户控件,从DataGrid继承,然后override它的onmousedown方法:
OnMouseDown(System.Windows.Forms.MouseEventArgs e)  
  
{  
  
DataGrid.HitTestInfo hti 
= this.HitTest(e.X, e.Y);  
  
if (hti.Type == DataGrid.HitTestType.Cell)  
  
{  
  
MouseEventArgs eNew 
= new  
  
MouseEventArgs(e.Button,e.Clicks,
2,e.Y,e.Delta);  
  
base.OnMouseDown(eNew);  
  
return;  
  
}
  
  
base.OnMouseDown(e);  
 
然后在你的窗体上添加这个控件,绑定数据后就可以了。

posted on 2006-10-20 21:36  KUDO  阅读(984)  评论(0编辑  收藏  举报

导航