class - How to use winform listbox to list declared objects in C#? -
i trying make listbox in winform use list of declared objects content source. choosing object should list properties in nearby text box reads properties of object. object list looks this:
public form1() { element gold = new element(); gold.property = "soft"; gold.metal = true; gold.name = "gold"; initializecomponent(); }
i told putting in main form way go this. have attempted far giving name string listbox use name object user select, , other 2 properties (gold.property = "soft"; , gold.metal = true; meant go in nearby textbox when item selected in listbox). don't know how this, sort of appreciated. @ base, knowing how listbox find object made , list it, great.
also, yes, assignment. things have outlined need done in way...there more assignment itself, stuck here.
use list<element> elements
store element, loop on each element , add name listbox.
add event handler listbox selected index changed, code should it. (remember check whether selected index -1 or not)
txtname.text = elements[listbox.selectedindex].name; txtproperty.text = elements[listbox.selectedindex].property;
Comments
Post a Comment