Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleMake a checkbox list
Keywordscheck box, CheckBox, list, check list
CategoriesControls
 
Use a ListView control. Use the items' SmallIcon properties to display checked and unchecked icons.
 
Private Enum IconValues
    iconUnchecked = 1
    iconChecked = 2
End Enum

Private Sub Form_Load()
Dim i As Integer

    ' Associate ImageList1 with the ListView's
    ' small icons.
    ListView1.SmallIcons = ImageList1
    ListView1.View = lvwList
    ListView1.LabelWrap = False

    ' Make some list items and set their
    ' SmallIcons to the unchecked icon.
    For i = 1 To 10
        ListView1.ListItems.Add , , "Item " & Format$(i), , _
            iconUnchecked
    Next i
End Sub

' Toggle the item's checked state.
Private Sub ListView1_ItemClick(ByVal Item As ListItem)
    With Item
        If .SmallIcon = 1 Then
            .SmallIcon = 2
        Else
            .SmallIcon = 1
        End If
    End With
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated