简体   繁体   English

C#事件,用于更改Winform中的其他字段

[英]C# Event for changing other fields in Winform

Im creating dynamic forms in my application. 我在我的应用程序中创建动态表单。 Im using DevExpress Controls like: 我正在使用DevExpress控件,例如:

            NumericUpDown controlNumUpDown = null;
            DateEdit controlDateEdit = null;
            TextEdit controlTextEdit = null;
            LookUpEdit controlComboBox = null;
            SimpleButton controlButton = null;
            MemoEdit controlMemo = null;
            GridControl controlGrid = null;
            CheckBox controlCheckBox = null;
            CheckedListBoxControl controlCheckedListBoxControl = null;
            RadioGroup controlRadioGroup = null;
            LabelControl controlStaticText = null;

Now every control value can rely on another- when the field is visible or not, enabled or not. 现在,每个控制值都可以依赖于另一个值-字段是否可见,是否启用。

So lets say we have date edit (fieldId=48), and a LookUpEdit (combobox). 假设我们有日期编辑(fieldId = 48)和LookUpEdit(combobox)。

Now Combobox have defined dynamic list as SQL query like: 现在,Combobox已将动态列表定义为SQL查询,例如:

Select * from indexes where inserted_date=Field.48 . Select * from indexes where inserted_date=Field.48

The list of items in combo box should be updated when date in another control changes. 当另一个控件中的日期更改时,组合框中的项目列表应更新。 Same goes for text editors, if Field.48 would be TextEdit it should work in the same way, same goes for other types of fields given in the code upon. 文本编辑器也是如此,如果Field.48将是TextEdit,则它应该以相同的方式工作,代码中给出的其他类型的字段也是如此。

Take care- its only an example, as i mentioned every control can rely on another, they can even go in infinite loop if user defines it badly (i dont care about that), same as one field can rely on 100 other fields. 请注意,这只是一个例子,正如我提到的,每个控件都可以依赖另一个控件,如果用户定义不好,它们甚至可以陷入无限循环(我不在乎),就像一个字段可以依赖其他100个字段一样。

So question is, what event is the best for that ? 所以问题是,什么活动最适合呢? So far i have used Leave Event of each control, but it doesnt work, if control is not enabled or not visible. 到目前为止,我已经使用了每个控件的“离开事件”,但是,如果控件未启用或不可见,它将无法正常工作。

Sometimes it is required to hide some field, like amountOfDollars (NumericEdit), but still other field like Checkbox (if checked, document is important) may rely on hidden field: amountOfDollars. 有时需要隐藏某些字段,例如amountOfDollars(NumericEdit),但是其他字段(如Checkbox)(如果选中,则文档很重要)可能仍依赖于隐藏字段:amountOfDollars。

Any suggestions? 有什么建议么? (all answers are welcome, it may be unsolvable by events...) (欢迎所有答案,可能无法通过事件解决...)

What you're trying to do isn't a new concept. 您尝试做的不是一个新概念。 You're trying to create a system of observable properties --this is the correct approach and design pattern for your requirement. 您正在尝试创建一个可观察属性的系统-这是满足您需求的正确方法和设计模式。

Google around and also take a look here: https://codereview.stackexchange.com/questions/132577/reactive-properties-for-easy-property-binding 谷歌周围,也可以在这里看看: https : //codereview.stackexchange.com/questions/132577/reactive-properties-for-easy-property-binding

The basic idea is to react not to an event, per se, but to property setter changes for particular controls. 基本思想是不对事件本身做出反应,而是对特定控件的属性设置器更改做出反应。 Many third-party components expose OnChange-type events for you to intercept particular property changes--others let you override the property-setter behavior. 许多第三方组件公开OnChange类型的事件,以供您拦截特定的属性更改-其他组件则使您可以覆盖属性设置器的行为。 Sometimes you will need to subclass the third-party control and wire-up your own handlers. 有时您需要将第三方控件分类,并连接自己的处理程序。

Your question is very broad, but the above should help steer you in the right direction even if the referenced link doesn't exactly meet your needs. 您的问题非常广泛,但是即使引用的链接不能完全满足您的需求,上述内容也可以帮助您朝正确的方向发展。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM