现在想在DataGird中选中一行,双击该行可以得到该行的行标并且弹出一个窗口,对该行数据进行更改,请问我如何选中一行并且响应双击事件?
我现在可以选中一行,可是一双击鼠标就跑到单元格里面去了,如何屏蔽单元格??
private void dataGrid1_CurrentCellChanged(object sender, System.EventArgs e)
{
this.dataGrid1.Select(this.dataGrid1.CurrentRowIndex);
}
我现在可以选中一行,可是一双击鼠标就跑到单元格里面去了,如何屏蔽单元格??
private void dataGrid1_CurrentCellChanged(object sender, System.EventArgs e)
{
this.dataGrid1.Select(this.dataGrid1.CurrentRowIndex);
}
对了,双击行列之间的分隔线可以,双击行头好像也可以,不过这还是不行啊,反正我已经放弃了。有好的办法通知我。
http://www.syncfusion.com/faq/windowsforms/search/689.aspx
MouseDown处理双击事件, 参考以下 If (e.Button == MouseButtons.Left && e.Clicks == 2)
{
MessageBox.Show(DataGrid2.CurrentCell.RowNumber.ToString() + " " + DataGrid2.CurrentCell.ColumnNumber.ToString())
}
{
dataGridView1.ReadOnly = true;
Form2 f = new Form2();
f.Show();
dataGridView1.ReadOnly = false ;
}
Knight94(愚翁) 和 Mark2Win(马客) 两位解决方法和起来就可以了 谢谢诸位!
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;
{
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");
}
}