Set Default Checked Items in a CheckedLIstBox VB.Net -


i have code retrieve data sql server checkedlistbox

    dim querystring string = "select facility database.dbo.facility"     dim connection new sqlconnection(connectionstring)     dim command new sqlcommand(querystring, connection)     connection.open()     dim datareader sqldatareader = command.executereader()     dim var new datatable     dim source new bindingsource     source.datasource = datareader     checklist_facility.datasource = source     checklist_facility.valuemember = "facility"     connection.close() 

the result works well, assume have result:

[ ]aa [ ]bb [ ]cc 

i check if there "bb" automatically checked "bb"

[ ]aa [x]bb [ ]cc 

i tried failed. likes

     each item in checkedlist_facility.items         if (item("facility").tostring() = "bbb")             checkedlist_region.selectedvalue = true     next 

to try if return string, tested code

for each item in checkedlist_facility.items     msgbox(item("facility").tostring()) next 

it return "aa", "bb" , "cc"

try following code

dim querystring string = "select facility database.dbo.facility" dim checkedvalue string = "bb" dim connection new sqlconnection(connectionstring) dim command new sqlcommand(querystring, connection)  connection.open()  dim datareader sqldatareader = command.executereader()  if datareader.hasrows     while datareader.read         dim facility string = datareader.item("facility").tostring()         dim checkedstate boolean = facility = checkedvalue          checklist_facility.items.add(facility, checkedstate)     loop end if  connection.close() 

Comments