Reducing Code size from ridiculous length

This is a discussion on Reducing Code size from ridiculous length within the C# Programming forums, part of the General Programming Boards category; I have several almost exact repeated sections of code. On my windows form, one of the tab pages has a ...

Reducing Code size from ridiculous length

I have several almost exact repeated sections of code. On my windows form, one of the tab pages has a large amount of combo boxes and text boxes to enter information. Its a basic game to be exact.

I have 16 lines of [combobox] [combobox] [textbox] [textbox] [textbox]

as you can imagine, any amount of code is gonna long and drawn out. You havent seen my code yet. It gets quite complex, to prevent the user making mistakes, guide them to the correct way of filling in these text boxes. It would still be huge overall anyway without the fancy bits.

Its the control names that are getting me on this one. How can I just have one instance of the above code, but linking it to a selectedIndexChanged event from 16 different comboboxes, each one affecting 16 different groups of comboboxes and textboxes?

Oh, and how can I overall speed up the rendering of controls on my windows form? This isnt slow at loading, but you can definitely see it load, a good description might be "a bit clunky".

After trying out that code, I can see what you are showing with that, but with me still being new to programming OOP overall, I am struggling to see how to link the changing of one combo box will affect the selection of another (on the same line).

but i have 16 lines of [combobox] [combobox] [textbox] [textbox] [textbox], the first combo box in each line only affects the other controls on the same line. These of course have numbers in their name. I can see what you have both said, its the controlling the relevant controls from whatever control is changed is the problem i am having.

example, selecting option 5 from the first combo box tells the other controls on the same line to enable, and what items to put in the second combobox of the same line.

basically, when i choose an item in combobox1line1, i want it to set the properties of other controls on the same line. So in the function that the event (that I understand) is called when you change an item in combobox 1, it must find the number at the end of the control that activated the event, and then apply that number to the end of the control name (ie. replacing the last number of the control inside the switch function in the example code).

I can see the 'find out what box commited the crime'. But I am having trouble with the 'shortened' version of, 'ok, box 2 did it, so only the boxes on the second line are affected'.