Solved

dynamic checkbox

Posted on 2007-03-19
3
195 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

728 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