现在想在DataGird中选中一行,双击该行可以得到该行的行标并且弹出一个窗口,对该行数据进行更改,请问我如何选中一行并且响应双击事件?
我现在可以选中一行,可是一双击鼠标就跑到单元格里面去了,如何屏蔽单元格??
private void dataGrid1_CurrentCellChanged(object sender, System.EventArgs e)
{
this.dataGrid1.Select(this.dataGrid1.CurrentRowIndex);
}

解决方案 »

  1.   

    我也遇到同样的问题,好像没有好办法。用2005的dataGridView吧
      

  2.   

    我试过n次了,连单击事件都没有,全都被cell里面的文本响应了。
    对了,双击行列之间的分隔线可以,双击行头好像也可以,不过这还是不行啊,反正我已经放弃了。有好的办法通知我。
      

  3.   

    ref:
    http://www.syncfusion.com/faq/windowsforms/search/689.aspx
      

  4.   

    双击是不行的要在MouseUp和MouseDown事件里面处理, MouseUp处理选中行, 代码参见楼上的链接, 
    MouseDown处理双击事件, 参考以下        If (e.Button == MouseButtons.Left && e.Clicks == 2)
            {
                MessageBox.Show(DataGrid2.CurrentCell.RowNumber.ToString() + " " + DataGrid2.CurrentCell.ColumnNumber.ToString())
            }
      

  5.   

    哦,你要继承下DataGridColumn,自己写一下重写一下Edit方法
      

  6.   

    有这么复杂吗,很久没发贴了.选择模式可以设为整行模式,避免进入单元格方式,置readonly=true,显示完后再置为false就可以啊.        private void dataGridView1_DoubleClick(object sender, EventArgs e)
            {
                dataGridView1.ReadOnly = true;
                Form2 f = new Form2();
                f.Show();
                dataGridView1.ReadOnly = false ;
            }
      

  7.   

    在csdn里面有,你search一下吧!以前我回答过这个问题
      

  8.   

    问题解决~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Knight94(愚翁)  和 Mark2Win(马客) 两位解决方法和起来就可以了 谢谢诸位!
      

  9.   

    解决了也不公布下,我公布我的方法:
    private void dataGrid1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
    {
    if(oldTime == 0)
    {
    oldTime = DateTime.Now.Ticks;
    }
    else
    {
    if(DateTime.Now.Ticks - oldTime < 3100100) MessageBox.Show("双击");
    }
    oldTime = DateTime.Now.Ticks; System.Drawing.Point pt = new Point(e.X, e.Y); 
      DataGrid.HitTestInfo hti = dataGrid1.HitTest(pt);
      if(hti.Type == DataGrid.HitTestType.Cell)
      { 
      //dataGrid1.CurrentCell = new DataGridCell(hti.Row, hti.Column); 
      dataGrid1.Select(hti.Row);
      }  
    }//开头加上:private long oldTime = 0;
      

  10.   

    private void dataGrid1_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
    {

    System.Drawing.Point pt = new Point(e.X, e.Y);
    DataGrid.HitTestInfo hti = dataGrid1.HitTest(pt);
    if(hti.Type == DataGrid.HitTestType.Cell && e.Button==MouseButtons.Left)
    {
    dataGrid1.CurrentCell = new DataGridCell(hti.Row, hti.Column);
    dataGrid1.Select(hti.Row);
    }
    }
    private void dataGrid1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
    {
    System.Drawing.Point pt = new Point(e.X, e.Y);
    DataGrid.HitTestInfo hti = dataGrid1.HitTest(pt);
    if(e.Button==MouseButtons.Left && e.Clicks==2 && hti.Type == DataGrid.HitTestType.Cell)
    {

    MessageBox.Show("DoubleClick");
    }

    }
      

  11.   

    怎么在datagrid里没有mouse down和mouse up的事件啊 我用的vs2003