4 Replies - 15104 Views - Last Post: 02 August 2019 - 06:57 AM Rate Topic: -----

#1 Jaycee twice   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 02-August 11

populate checkedlistbox with items form database

Posted 02 October 2011 - 08:02 PM

how can i dynamically populate checkedlistbox with items from the database?
Is This A Good Question/Topic? 0
  • +

Replies To: populate checkedlistbox with items form database

#2 smohd   User is offline

  • Critical Section
  • member icon


Reputation: 1825
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: populate checkedlistbox with items form database

Posted 02 October 2011 - 08:15 PM

Ya, probably you can.Just:
-connect to the database, read your data using data reader.
- then use ListBoxName.Items.Add() to add those data reader items
- just dont forget to start updating ListBoxName.BeginUpdate()
Was This Post Helpful? 0
  • +
  • -

#3 Jaycee twice   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 02-August 11

Re: populate checkedlistbox with items form database

Posted 02 October 2011 - 08:19 PM

Dim mydata As New DataTable
With lstactivity
mydata = myquery.runQuery("select act_name AS 'Activity' from issnew.mcars_activities ORDER by act_name ASC")
.Items.Clear()
For x As Integer = 0 To mydata.Rows.Count - 1
.Items.Add(CStr(mydata.Rows(x).Item(0)))
Next
End With


-----i have this code but then, nothing display in the checkedlistbox....
Was This Post Helpful? 0
  • +
  • -

#4 smohd   User is offline

  • Critical Section
  • member icon


Reputation: 1825
  • View blog
  • Posts: 4,627
  • Joined: 14-March 10

Re: populate checkedlistbox with items form database

Posted 02 October 2011 - 08:27 PM

Try something like
Dim command As New SqlCommand("query here",connection)
Dim reader As SQLDataReader = command.ExecuteReader()
'now use reader to populate your list box with something like
 While myreader.Read
      name.BeginUpdate()
      name.Items.Add(myreader.Item("subjectName"))
      name.EndUpdate()
End While

Was This Post Helpful? 1
  • +
  • -

#5 OgwoGP   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 02-August 19

Re: populate checkedlistbox with items form database

Posted 02 August 2019 - 06:57 AM

View Postsmohd, on 02 October 2011 - 08:27 PM, said:

Try something like
Dim command As New SqlCommand("query here",connection)
Dim reader As SQLDataReader = command.ExecuteReader()
'now use reader to populate your list box with something like
 While myreader.Read
      name.BeginUpdate()
      name.Items.Add(myreader.Item("subjectName"))
      name.EndUpdate()
End While



That is the best for Checklist update I have seen. Thank you.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1