in winforms, I can create an array or list of buttons, and assign a click event to them in a for-loop, and simply pass the control index as a parameter, and it works great, but in ETO the sender is ALWAYS the last index number of the loop.(+1) in this case
example pseudocode (the winforms version very similar)
//setup a new List<Button> buttonlist
//setup a new List<ImageView> images
for(int i=0;i<6){
buttonlist.Add(new Button {Text = "Click to Add", Size = ConstructionSizeControls });
buttonlist[i].Click += (sender, e) => AddPart(i);
images.Add(new ImageView());
}
but, the sender index passed in this case is ALWAYS 6, irrespective of the button clicked.
Any thoughts on how this owrks in ETO? The controls in each “division” are all interelated and index each other in my winforms code so dropdown[i] == button[i] == image[i] etc. and the number of parts can vary by user simply adding more so they must live in the list and be indexable by the list.
Note that you’re not passing in sender to AddPart, but i.
I’d adapt AddPart so that you actually pass in the sender. Before you set the event handler for Click I’d add a Tag to the Button instance. Set it to your i. In your AddPart you’d use the Tag - since it’ll be object you’ll have to cast it back to int.
edit:
I use Tag in one place where I have a bunch of controls all using the same event handler:
Note checking of the sender type and then casting of the Tag.
for future reference reasons for other viewers of the thread, I compiled some code using the windows colours in the conduit instead fo the ETO colours and they worked fine.