vb.net - How to sort the sequence of checkbox -
i have 2 checkboxes. if check cb1 first , cb2 next, listbox should display data of checkboxes in order of checked sequence.
public class form1 private sub button1_click(sender object, e eventargs) handles button1.click if cb1.checked = true , cb2.checked = false listbox1.items.add(cb1.text) if cb1.checked = true , cb2.checked = true listbox1.items.add(cb1.text) end if elseif cb2.checked = true , cb1.checked = false listbox1.items.add(cb2.text) if cb2.checked = true , cb1.checked = true listbox1.items.add(cb1.text) end if end if end sub end class
if 1 checkbox checked displays data, if both checked there's no data displayed in list box.
you're question not clear enough me sure of want here solution question interpreted:
your code checking if both true nested within if statements wouldn't run if both true. also, dont put end if @ end of elseif if have more criteria come.
fixed code:
private sub button1_click(sender system.object, e system.eventargs) handles button1.click if cb1.checked = true , cb2.checked = false listbox1.items.add(cb1.text) elseif cb1.checked = true , cb2.checked = true listbox1.items.add(cb1.text) listbox1.items.add(cb2.text) end if if cb2.checked = true , cb1.checked = false listbox1.items.add(cb2.text) elseif cb2.checked = true , cb1.checked = true listbox1.items.add(cb2.text) listbox1.items.add(cb1.text) end if end sub
you have better luck if made event happen automatically after each 1 checked. code run once, if have 1 checked , code runs, if other 1 checked, code won't run again unless have in sort of loop (until loop work).
Comments
Post a Comment