c# - How can I pair objects to radio buttons? -
i'm working on small form app, , have "paired" radio buttons lists in common class. purpose of turn on/off corresponding list
public class mytype { public radiobutton button { get; set; } public listbox list { get; set; } }
i proceed create these pairs through loop inside array
for (int = 0; < broj_botuna; i++) { thearray[i] = new mytype(); }
i use common event handler radio buttons:
private void test_checkedchanged(object sender, eventargs e) { var xx = sender radiobutton; //do stuff positioninarray = array.indexof(thearray, xx); }
except last line of code "xx" should of type "mytype" , not "radiobutton" managed retrieve.
so tell me how reference "radiobutton" "mytype"? or there better alternative?
you can use array.findindex
like:
var positioninarray = array.findindex(thearray, b => b.button == xx);
Comments
Post a Comment