我正在使用 DataGridView 控件处理 WinForm 客户端。我注意到用户必须单击一次才能选择单元格,然后再次单击才能对其进行编辑。将其更改为单击编辑模式的方法是什么?我以为我以前见过这样的东西,但不记得名字了。
最佳答案
我注意到 EditMode.EditOnEnter
有问题
它偏向了很多 DataGriView 的默认行为,令人恼火。
其中,即使显式调用 EndEdit 方法(您必须单击另一个控件以使 datagridview 单元格失去焦点),编辑过的单元格仍保持编辑模式。
以下代码工作得非常好,因为它使您可以通过单击任何单元格进行编辑,然后通过按 Enter 键或在 DGView 外部单击来结束编辑(就像您在默认行为中所做的那样)
干得好 :
private void myDatagridView_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
hitTestInfo = myDatagridView.HitTest(e.X, e.Y);
if (hitTestInfo.Type == DataGridViewHitTestType.Cell)
myDatagridView.BeginEdit(true);
else
myDatagridView.EndEdit();
}
}
关于.net - DataGridView - "Cell Selection Style"- 编辑单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1379409/