Solved

dynamic checkbox

Posted on 2007-03-19
3
187 Views
Last Modified: 2013-12-26
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.
0
Comment
Question by:jduclosjduclos
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
jkaios earned 125 total points
ID: 18751449
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.Clear
      .ListItems.Clear
      '---------------------
      .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
      DoEvents
      Set oItem = ListView1.ListItems.Add
      oItem.Text = rs("ID")
      oItem.SubItems(1) = rs("Description")
      rs.MoveNext
   Loop
   
End Sub
'---------------------------------------------------------------------------------------------------------
0
 

Author Comment

by:jduclosjduclos
ID: 18772252
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?
0
 

Author Comment

by:jduclosjduclos
ID: 18808998
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))
            xCLBResource.Items.Add(items)
            r = r + 1
        End While
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now