Simplify Your Code with Reflection: Table 1: Accommodate Different IsDirty Scenarios

The approach described in this article lets you accommodate determining whether changes occurred on a form in any of several different scenarios. This means that you must create the code and the corresponding data structure that can handle all these various permutations. This list of scenarios describes various situations that you must take into account when reading data from controls.

Scenario 1 If the control can have multiple values selected, then call a method to read all the selected values. An example of this is the CheckedListBox control.
Scenario 2 You might have to read from one property to determine if the control can either have one or multiple values selected. Based on this property, you might have to read the data from one property, or you may have to call a method to read all the selected values. An example of this case would be a ListBox control. You first check the SelectionMode property to see whether it's equal to "One." If it is, you call the method to read all selected values. Otherwise, you just read the SelectedIndex property.
Scenario 3 You might have to check a property on some controls to see whether it's equal to a specific value. Depending on that value, you either read from "Property 1" or "Property 2." An example of this is a ComboBox, where the DropDownStyle property is set to "DropDownList." If the list is set to "DropDownList," then you read the SelectedIndex property; otherwise, you read the Text property.
Scenario 4 Some controls might require that you read from two properties to determine whether or not the control is dirty. For example, the MonthCalendar control requires that you read from the SelectionStart and SelectionEnd properties.
Scenario 5 The final case occurs when you have a normal TextBox, CheckBox, or RadioButton control, where you simply read the data from a single property.
comments powered by Disqus
Upcoming Events

.NET Insight

Sign up for our newsletter.

I agree to this site's Privacy Policy.