最近,用C# C/S方式windows编程,本人是想利用DataGrid控件检索数据,然后再又击行后调出详细信息,但不知DataGrid如何接收鼠标收双击事件,请赐教。 本人是C#的初学者。

解决方案 »

  1.   

    不知道这个是否对你有帮助,这个就是通过代码去 DataGrid第一列 单元格中的值,然后这里面的值就是数据库中的ID 点他后,弹出详细信息的窗口。然后在弹出窗口的事件中显示当前数据库ID的详细信息private void dataGrid1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
    {
    try
    {
    cellValue = this.dataGrid1[this.dataGrid1.CurrentRowIndex,0];
    // System.Drawing.Point pt = new Point(e.X, e.Y); 
    // DataGrid.HitTestInfo hti = this.dataGrid1.HitTest(pt); 
    // dataGrid1.CurrentCell = new DataGridCell(hti.Row, 1); 
    // dataGrid1.Select(hti.Row); 
    // cellValue = dataGrid1[hti.Row, 0]; 
    // MessageBox.Show(cellValue.ToString());
    //////
    // frmbase_cfrm = new kehu_frmbase_cfrm(this,cellValue.ToString());
    // this.frmbase_cfrm.Show();
    // this.tmp = 2;
    }
    catch (System.Exception myEr)
    {
    MessageBox.Show(myEr.ToString());
    }
    }
      

  2.   

    http://community.csdn.net/Expert/topic/3940/3940751.xml?temp=.6154444
      

  3.   

    C/S的我不太熟,但看了一下,datagrid是有DoubleClick事件的
    你是想看事件的原理的吗?
      

  4.   

    System.Drawing.Point pt = new Point(e.X, e.Y); 
    DataGrid.HitTestInfo hti = this.dgResult.HitTest(pt); 
    if(hti.Type == DataGrid.HitTestType.Cell) 
    {
    this.dgResult.CurrentCell = new DataGridCell(hti.Row, hti.Column);
    this.dgResult.Select(hti.Row);
    }
    在mouse_up里面加入上面的这些,可以保证能够触发doubleclick,而不是选中行的内容。