• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 203
  • Last Modified:

dynamic checkbox

I have an app that pulls an id number and description.  This info pull from an sql server.  I also want to add a checkbox per each ID, how would I do this.
  • 2
1 Solution
jkaiosIT DirectorCommented:
Assuming that the name of your connection object is oCONN and the field names to retrieve from the table are ID and Description.

Now, the following example use the List View control in Microsoft Common Controls 6.0
Add a list view control to the form and then use the code below to populate it.
Rename [YOUR TABLE] to the actual name of your table.

Again, assuming that you have already made a connection to the database.
Private Sub Form_Load()
   On Error Resume Next
   Dim rs As New ADODB.Recordset
   Dim xx As String
   Dim oItem As MSComctlLib.ListItem
   With ListView1
      .View = lvwReport
      .GridLines = True
      .LabelEdit = lvwManual
      .Checkboxes = True
      .FullRowSelect = True
      .ColumnHeaders.Add , , "ID#"
      .ColumnHeaders.Add , , "Description"
   End With
   xx = "SELECT ID, Description FROM [YOUR TABLE]"
   rs.Open xx, oCONN, adOpenForwardOnly, adLockReadOnly, adCmdText
   Do Until rs.EOF
      Set oItem = ListView1.ListItems.Add
      oItem.Text = rs("ID")
      oItem.SubItems(1) = rs("Description")
End Sub
jduclosjduclosAuthor Commented:
what about using a checklistbox, how would i use that with data from a MSSql table, and which is better dynamic checkboxes or the checklist box?
jduclosjduclosAuthor Commented:
Ok I have figured out what i needed to do for a dynamic checkedlistbox.
 'This is used populate the checklistbox
        Dim items As String
        Dim r As Integer = 0
        Dim c As Integer = 1
        While r < xResourceT.GetData.Rows.Count
            items = CStr(xResourceT.GetData.Rows(r).Item(c))
            r = r + 1
        End While
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now