c# - Getting selected item from a listbox -
my issue pretty weird, trying write string selected item of list, , string empty.
this code:
void loader(methodinfo[] metharr) { //string abba = ""; listbox1.items.clear(); //loop (int = 0; < metharr.length; i++) { ab = ab.appendline(metharr[i].tostring()); //abba = ab.tostring(); listbox1.items.add(ab); ab.clear(); } } private void button1_click(object sender, eventargs e) { checker(); } private void button2_click(object sender, eventargs e) { string = listbox1.getitemtext(listbox1.selecteditem.tostring()); string b = listbox1.selecteditem.tostring(); string c = "dummy"; messagebox.show(a + b + c); }
if use selectedindex show me index, otherwise i'll c string
this full code : http://pastebin.com/i0mcetzz
debug - edit2
don't add string builder list, that's object reference object collection. use tostring()
method (as have commented out)
see example:
using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.threading.tasks; using system.windows.forms; namespace windowsformsapplication3 { public partial class form1 : form { public form1() { initializecomponent(); } private void button1_click(object sender, eventargs e) { stringbuilder builder = new stringbuilder(); (int = 0; < 10; i++) { builder.append(i); listbox1.items.add(builder); builder.clear(); } (int = 0; < 10; i++) { builder.append(i); listbox2.items.add(builder.tostring()); builder.clear(); } } private void button2_click(object sender, eventargs e) { string = listbox1.getitemtext(listbox1.selecteditem.tostring()); string b = listbox1.selecteditem.tostring(); string c = listbox1.getitemtext(listbox1.selecteditem); string d = listbox2.getitemtext(listbox2.selecteditem.tostring()); string f = listbox2.selecteditem.tostring(); string g = listbox2.getitemtext(listbox2.selecteditem); messagebox.show("1:" + + b + c + "\r\n2: " + d+ f + g); } } }
Comments
Post a Comment