i'm having problems vb.
i'm trying create code keep checked items in checkedlistbox while search through it. have array stores names of checked items, when use ckeckedlistbox.setcheckeditem() method, need use indices, , change every time search in list box.
this have far:
dim checkeditems(1000) string if txtsearch.text.length = 1 = 0 1000 if lstverktyg.checkeditems.item(i) = "" exit end if checkeditems(i) = lstverktyg.checkeditems.item(i) next end if dim connection new mysqlconnection("server=" & my.settings.host & ";user id=" & my.settings.user & "; password=" & my.settings.pass & "; port=3306; database=" & my.settings.db & "; pooling=false") try connection.open() catch ex mysqlexception exit sub end try dim reader mysqldatareader dim query mysqlcommand dim resultsnumber integer = 0 lstverktyg.items.clear() query = new mysqlcommand("select `namn` `verktyg` `namn` '%" & txtsearch.text.replace("'", "\'") & "%' limit 300;", connection) reader = query.executereader() while (reader.read()) lstverktyg.items.add(reader.getstring("namn")) end while if reader isnot nothing reader.close() = 0 1000 if checkeditems(i) = "" exit end if if lstverktyg.getitemchecked(i) end if next what do?
here simple example of how can that. let's fill checkedlistbox control items, this:
checkedlistbox1.items.addrange({"item 1", "item 2", "item 3"}) then, show form , let user check whatever items choose. then, when want reload list , retain items checked, can this. first, want create list of checked items:
dim checkeditems new list(of object)(checkedlistbox1.checkeditems.count) each object in checkedlistbox1.checkeditems checkeditems.add(i) next then, can safely clear items checkedlistbox:
checkedlistbox1.items.clear() then, can reload list refreshed data, instance:
checkedlistbox1.items.addrange({"item 1", "item 2", "item 3", "item 4"}) then, can loop through items in checkedlistbox , check each 1 if exists in saved list of checked items:
for integer = 0 checkedlistbox1.items.count - 1 if checkeditems.contains(checkedlistbox1.items(i)) checkedlistbox1.setitemchecked(i, true) end if next so, apply method code example, this:
dim checkeditems new list(of object)(lstverktyg.checkeditems.count) if txtsearch.text.length = 1 each object in lstverktyg.checkeditems if = "" exit checkeditems.add(i) next end if dim connection new mysqlconnection("server=" & my.settings.host & ";user id=" & my.settings.user & "; password=" & my.settings.pass & "; port=3306; database=" & my.settings.db & "; pooling=false") try connection.open() catch ex mysqlexception exit sub end try dim reader mysqldatareader dim query mysqlcommand dim resultsnumber integer = 0 lstverktyg.items.clear() query = new mysqlcommand("select `namn` `verktyg` `namn` '%" & txtsearch.text.replace("'", "\'") & "%' limit 300;", connection) reader = query.executereader() while (reader.read()) lstverktyg.items.add(reader.getstring("namn")) end while if reader isnot nothing reader.close() integer = 0 lstverktyg.items.count - 1 if checkeditems.contains(lstverktyg.items(i)) lstverktyg.setitemchecked(i, true) end if next
Comments
Post a Comment