Bartosz
Bartosz

Reputation: 1820

C# Event for changing other fields in Winform

Im creating dynamic forms in my application. Im using DevExpress Controls like:

            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).

Now Combobox have defined dynamic list as SQL query like:

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.

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.

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.

Any suggestions? (all answers are welcome, it may be unsolvable by events...)

Upvotes: 0

Views: 262

Answers (1)

Jazimov
Jazimov

Reputation: 13282

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

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. 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.

Upvotes: 1

Related Questions