如何在关闭表单之前强制执行DataGridView单元格验证? [英] How to force DataGridView cell validation before closing form?
本文介绍了如何在关闭表单之前强制执行DataGridView单元格验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个可以编辑的 DataGridView
。编辑后,当我单击Enter或选择另一个单元格时,发生 CellValueChanged
事件,然后保存此新值。
I have a DataGridView
that I can edit. After editing, and when I click Enter or select another cell, CellValueChanged
event occurs and I save this new value.
我的问题:如果我更改单元格值并在不单击Enter或不选择其他单元格的情况下关闭表格,则不会保存该最后一个值。
My problem : If I change cell value and close form without click Enter or select another cell before, this last value isn't saved.
有没有办法解决?
推荐答案
假设您有 DataTable
作为<$ c $ DataGridView
中的c> DataSource ,然后使用以下代码进行验证并结束编辑:
Assuming you have a DataTable
as DataSource
of your DataGridView
, then use the following code to validate and end edit:
this.Validate();
dataGridView1.BindingContext[yourDatTable].EndCurrentEdit();
这篇关于如何在关闭表单之前强制执行DataGridView单元格验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文