【问题标题】:currentCell to remain the same if validation fail. - CellEndEdit Event如果验证失败,currentCell 保持不变。 - CellEndEdit 事件
【发布时间】:2011-04-29 03:07:30
【问题描述】:
我有一个数据网格视图供用户输入。
例如,列是“姓名”、“出生日期”...
对于“出生日期”部分,我已经实现了验证...
我想让用户在被允许离开单元格之前必须输入有效的“出生日期”。这意味着一旦他们进入牢房,他们必须提供有效的“出生日期”然后他们才能继续前进。
想知道如何做到这一点,我尝试将 DGV.currentCell 设置为“CellEndEdit”事件中的预期单元格。但它给了我以下错误:“操作无效,因为它导致对 setcurrentcelladdresscore 函数的可重入调用”
【问题讨论】:
标签:
vb.net
validation
datagridview
【解决方案1】:
我相信您可以通过使用 CellValidating
来实现这一点
void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
if(e.ColumnIndex == 3)
{
e.FormattedValue // Check your date validation against this value
e.Cancel = true; // set this to true if validation fails
}
}
这将有助于在用户输入错误的情况下将焦点保留在同一单元格中。