Csharp/C#教程:CancelEdit不会将注意力集中在DataGridView c#中的已编辑单元格上分享


CancelEdit不会将注意力集中在DataGridView c#中的已编辑单元格上

当我在DataGridView的单元格中输入一些值并单击另一个单元格时,将执行cellvalidating事件处理程序代码。 即使validation填充,我点击的单元格也会突出显示。 我的要求是单元格应保持选中状态,并且在删除无效值后,光标应在单元格中闪烁以进行编辑。 如果validation失败,请使用以下代码:

DataGridView1.CancelEdit(); 

我试过添加

 DataGridView1.CurrentCell.Selected = true; DataGridView1.BeginEdit(true); 

您需要使用e.Cancel = true如下所示。

 private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) { int i; if (!int.TryParse(e.FormattedValue.ToString(), out i)) { e.Cancel = true; MessageBox.Show("Please input a integral number.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } 

我用上面的解决方案改变了我的代码并且它有效:

上述就是C#学习教程:CancelEdit不会将注意力集中在DataGridView c#中的已编辑单元格上分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

 private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) { DataGridView1.CancelEdit(); e.Cancel = true; DataGridView.BeginEdit(true); } 

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/988419.html

(0)
上一篇 2021年12月23日
下一篇 2021年12月23日

精彩推荐