and I had another area in the code that looked like this:
After looking through this code I realized that the private void BuildReferenceDropDownList – from the drop down and the private void buildCheckBoxList – from the Check Box were almost identical, the only difference between the two was the argument being pasted in, the dropdown was receiving the dropdown control and the checkbox was receiving the checkbox control. Another minor difference was that the Dropdown had an added item at the beginning of the selection.
Once the gerbil in my head started running and I realized that both of this object derive from the ListControl object(ButtonList, ListBox, & RadioButtonList also derive from ListContol), it made my job of refactoring this a lot easier. I created a single method that accepts a ListControl and the Generic List in as arguments , then returns a ListControl back to the control that called it:
Look at line 11, here I am checking the type of the listcontrol being past into the method and if it is a dropdownlist I am able to add the line to the Drop Down.
To call this method we made the code look for the dropdown like this:
And the Checkbox Control look like this:
What made this easier was that fact that all of the look ups were centralized in one table, which means that List<T> is a single business object. I am going to research and see if I can accept any List<T>. So if you happen to have a single Business Object that is populating all of our ListControls consider using this. Of cource if you have a better way, please share it I am always looking for an easier way of doing something.