简体   繁体   English

在更改显示的内容之前,如何检查 winform 上的所有控件以确保它们都没有被编辑?

[英]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.

相关问题 Winform:如何仅在加载所有控件后才显示表单控件? - Winform: How to display form controls only when all controls have been loaded? 如何至少在显示窗体的框架之前不加载窗体的控件? - How can I make a form's controls not load until at least the frame of the form has been displayed? 如何知道所有控件何时加载并显示? - How do I know when all controls have loaded and displayed? 在显示之前查看TextView有多少行 - Check how many lines TextView will have before it's displayed 如何确定全局键盘挂钩是否已断开连接? - How to make sure if global keyboard hook have been disconnected? 清除容器的Controls属性并确保正确处置控件的最安全方法是什么? - What is the safest way to clear a container's Controls property and make sure the controls are properly disposed? 如何确保测试启动的所有线程在完成之前停止 - How to make sure that all the threads started by the test(s) are stopped before completion 如何在访问任何页面之前检查以确保客户已完成任务 - How do I check to make sure the customer has done a task before they visit any page 在winform上找到隐藏的控件并使它们在运行时可见? - find hidden controls on winform and make them visible on runtime? 如何使控件符合Winform和Webform? - How to make a controls compliant for winform and webform?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM