【发布时间】:2015-10-09 10:07:50
【问题描述】:
我的目标是在我的 DataGridView 上有一个友好的验证流程。
当用户为某个单元格输入不正确的值时,我想:
- 退出编辑模式
- 还原修改(即从单元格中恢复原始值)
- 显示错误消息
我目前正在使用 CellValidating 事件来防止单元格更新其值,但我无法退出编辑模式。然后该单元格正在等待一个正确的值,并且不会让用户简单地取消和恢复他的操作...
这是验证方法的样子:
private void dataGridViewMsg_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
[...] // Here, treatment determines is the new cell value isValid or not
if (!isValid)
{
MessageBox.Show("The value entered is incorrect.", "Modification aborted");
e.Cancel = true;
dataGridViewMsg[e.ColumnIndex, e.RowIndex].IsInEditMode = false; // Someway, what I would like to do
return;
}
}
如何继续使单元格恢复其原始值而不需要我跟踪该值?
【问题讨论】:
标签: c# winforms datagridview