[英]How would I check all the controls on a winform to make sure none of them have been edited before changing what's displayed?
Technologies: C#, .Net, Winforms技术:C#、.Net、Winforms
I have a main form that pulls data from a database, and populates numerous different controls.我有一个从数据库中提取数据并填充许多不同控件的主窗体。 Labels, Textboxes, DataRepeaters, DataGridViews, and tabs filled with those kinds of controls as well.
标签、文本框、DataRepeaters、DataGridViews 和选项卡也填充了这些类型的控件。
However, the data is also being pulled in such a way that there are multiple "records" on this form being navigated by a BindingNavigator.但是,数据也以这样一种方式被提取,即在此表单上有多个“记录”由 BindingNavigator 导航。
Because of the structure of my code, I can't easily call a DataAdaptor.update() on whatever control is being validated, (using it's associated DataTable) so I'm just going to use a commit button instead.由于我的代码结构,我不能轻易地在任何正在验证的控件上调用 DataAdaptor.update() (使用它的关联 DataTable),所以我只使用提交按钮。
What I'd like to know is "How do I check all the controls to see if they've been edited?"我想知道的是“如何检查所有控件以查看它们是否已被编辑?”
I'm using the binding Navigator buttons as the trigger to "FindEditedControls()"我正在使用绑定导航器按钮作为“FindEditedControls()”的触发器
Current Solution:当前解决方案:
DataTable dt = db.GetTable();
dt.RowChanged += new DataRowChangeEventHandler(dtUpdated);
private void dtUpdated(object sender, DataRowChangeEventArgs e)
{
needsCommit = true;
}
And the button just checks the needsCommit boolean variable.按钮只检查 needsCommit boolean 变量。 If it's true, then it asks the user to commit the changes before continuing.
如果是真的,那么它会要求用户在继续之前提交更改。 If they click "Yes" then it commits the data to the database.
如果他们单击“是”,则它将数据提交到数据库。
If this is what you were getting, I want to thank you.如果这是你得到的,我要感谢你。 This works very nicely with DataGridViews.
这与 DataGridViews 配合得非常好。 Now to test it with standard form controls.
现在使用标准表单控件对其进行测试。
Hook up to the DataTable.RowChanged
event.连接到
DataTable.RowChanged
事件。 When it fires, one of your controls has been edited.当它触发时,您的一个控件已被编辑。
Then, you can check the DataRow.RowState
property for a value of DataRowState.Modified
for the rows you are binding to.然后,您可以检查
DataRow.RowState
属性以获取要绑定到的行的DataRowState.Modified
值。
assign a signature to every control from data bounded to it then check that signature with the values of the control.从绑定到它的数据中为每个控件分配一个签名,然后使用控件的值检查该签名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.