c# - Get property of listbox item -


i making project in winforms. have listbox populated on run, custom class objects list. each object, have associated button. want program return 1 of properties of associated object in listbox, when button clicked. want select item in listbox.

population of listbox:

 private void updatelist()  {      listbox.items.addrange(custom_list.toarray());  } 

the event fired when clicking associated button:

associatedbutton.mouseup += (sender, eventargs) => {     button btn = (button)sender;     (int j = 0; j < listbox.items.count; j++)     {         if (listbox.getitemtext(j) == btn.tag.tostring())         {             listbox.selecteditem = j;         }     } } 

the point of code be, either myobject.id property (which string) of given object in list, or displayed text in listbox item (these 2 identical). btn.tag created store string id value of corresponding object. listbox.getitemtext(j) (or listbox.items(j).tostring()) not seem return value. not throw exception, if construct skipped. solution this?


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

Error while updating a record in APEX screen -

c - Creating referenced table element -