.net - Visual Basic Iterating Over a ListBox with an Event Listener -
i have listbox containg list of items,i wondering how create handler can iterate listbox whenever event happen.
have following code read file listbox.
private sub load_file_to_listbox(byval sender system.object, byval e system.eventargs) handles load_file_to_listbox.click dim r new io.streamreader("c:\users\resu\desktop\test.txt") while (r.peek() > -1) lb1.items.add(r.readline) end while r.close() end sub
here event handler code:
private sub button2_click(byval sender system.object, byval e system.eventargs) handles button2.click textbox1.text = " " textbox1.text &= listbox1.selecteditems.item(i).tostring = + 1 end sub
i
declared global variable keep track of next item in listbox
. want read next item listbox
, put textbox
whenever button2 clicked.
kindly me in modifying code make work.
if understand correctly, problem lies following line of code:
'this line of code looks @ of items have been 'selected in list box, , out of of selected 'items select item @ index i. textbox1.text &= listbox1.selecteditems.item(i).tostring
because code looking @ selected items only , not all items code not behaving expect. instead, use following line of code:
textbox1.text &= listbox1.items(i).tostring()
Comments
Post a Comment