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

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -