Customizable event handler for dynamically created combo box

  • Thread starter Thread starter SagaV9
  • Start date Start date
S

SagaV9

Guest
Hi all!

I am using C# 2015 to build a Windows form app with an SQL Server back end. The client app is a read-only app with screens that display information from the database. Most of the screens are very similar. Because of this I decided to create one generic form and a class that creates an object (packet) with the information necessary for the form to create the needed UI elements.

Up to now, it works, but I need to add a drop down list (combobox) to the generic form. Depending on the form type, the SelectedIndexChanged event will perform different tasks. One possible way of doing this, which I'd rather avoid if at all possible, is to hard code the functionality of each form type into the event and then use a switch/case statement to perform different tasks according to the form type.

A more acceptable solution is to code the event handler in the class that builds the packet for the specific form, pass the event handler with the packet and then have the generic form assign that handler to the newly created combobox. The event handler needs to be able to access UI elements of the generic form (specifically the combobox and the data view grid).

I believe that this is entering the realm of delegates, but I have not had any significant experience with delegates and need the expertise of this forum to orient me as to which is the best way to proceed with this project. Any suggestions or references to material that I can read to help me resolve this issue are greatly appreciated. Thank you, Saga.


You can't take the sky from me

Continue reading...
 
Back
Top