Home

Checked List Boxes

 

Characteristics of a List Box

 

The Scroll Bars

If you provide a longer list than the list box' height can display, it would have a vertical scroll bar. Here is an example:

Imports System.Drawing
Imports System.Windows.Forms

Module Exercise

    Public Class Starter
        Inherits Form

        Private lbxFamily As ListBox

        Dim components As System.ComponentModel.Container

        Public Sub New()
            InitializeComponent()
        End Sub

        Public Sub InitializeComponent()

            lbxFamily = New ListBox()
            lbxFamily.Location = New Point(12, 12)
            lbxFamily.Items.Add("Son")
            lbxFamily.Items.Add("Daughter")
            lbxFamily.Items.Add("Father")
            lbxFamily.Items.Add("Mother")

            Dim strMembers As String() = _
                   { _
                       "Niece", "Nephew", "Uncle", "Aunt", _
                       "Grand Father", "Grand Mother" _
                   }
            lbxFamily.Items.AddRange(strMembers)

            Controls.Add(lbxFamily)

        End Sub

    End Class

    Function Main() As Integer

        Dim frmStart As Starter = New Starter

        Application.Run(frmStart)

        Return 0
    End Function

End Module

This would produce:

A List Box With a Vertical Scroll Bar

At design time, if just one or a few items are hidden by the scroll bar, you can heighten it if the form provides more space.

Consider the following example:

Imports System.Drawing
Imports System.Windows.Forms

Module Exercise

    Public Class Starter
        Inherits Form

        Private lbxBook As ListBox
        Private lblTitle As Label

        Dim components As System.ComponentModel.Container

        Public Sub New()
            InitializeComponent()
        End Sub

        Public Sub InitializeComponent()

            lblTitle = New Label()
            lblTitle.Text = "Book Titles"
            lblTitle.Location = New Point(12, 12)

            lbxBook = New ListBox()
            lbxBook.Location = New Point(12, 36)
            lbxBook.Items.Add("College Algebra")
            lbxBook.Items.Add("Finite Mathematics")
            lbxBook.Items.Add("Mathematical Structures")
            lbxBook.Items.Add("MCAD 70-316 Training Guide")
            lbxBook.Items.Add("C++ Builder 6 Developer's Guide")

            Controls.Add(lblTitle)
            Controls.Add(lbxBook)

        End Sub

    End Class

    Function Main() As Integer

        Dim frmStart As Starter = New Starter

        Application.Run(frmStart)

        Return 0
    End Function

End Module

This would produce:

A list box with wide items

If at least one of the items of the list box is wider than the width of the control, the right side(s) of that (those) may disappear. To allow the user to see the hidden part of the item(s), you should display a horizontal scroll bar. To support this, the ListBox class is equipped with a Boolean property named HorizontalScrollbar. To make a list box display a horizontal scroll bar, at design time, access the Properties window for the list box and set its HorizontalScrollbar property to True. You can also do this programmatically. Here is an example:

Public Sub InitializeComponent()

            lblTitle = New Label()
            lblTitle.Text = "Book Titles"
            lblTitle.Location = New Point(12, 12)

            lbxBook = New ListBox()
            lbxBook.Location = New Point(12, 36)
            lbxBook.Items.Add("College Algebra")
            lbxBook.Items.Add("Finite Mathematics")
            lbxBook.Items.Add("Mathematical Structures")
            lbxBook.Items.Add("MCAD 70-316 Training Guide")
            lbxBook.Items.Add("C++ Builder 6 Developer's Guide")

            lbxBook.HorizontalScrollbar = True

            Controls.Add(lblTitle)
            Controls.Add(lbxBook)

End Sub

This property allows the operating system to find the widest item in the list and provide a horizontal scroll bar that is long enough to display each item when the user scrolls to the right. The above code would produce:

A List Box With a Horizontal Scroll Bar

If the list of items requires it, the list box would display both the vertical and the horizontal scroll bars. Here is an example:

Public Sub InitializeComponent()

            lblTitle = New Label()
            lblTitle.Text = "Book Titles"
            lblTitle.Location = New Point(12, 12)

            lbxBook = New ListBox()
            lbxBook.Location = New Point(12, 36)
            lbxBook.Items.Add("College Algebra")
            lbxBook.Items.Add("Finite Mathematics")
            lbxBook.Items.Add("Mathematical Structures")
            lbxBook.Items.Add("MCAD 70-316 Training Guide")
            lbxBook.Items.Add("C++ Builder 6 Developer's Guide")
            lbxBook.Items.Add("La Bible de Jérusalem")
            lbxBook.Items.Add("Patterns for a Purpose")

            lbxBook.HorizontalScrollbar = True

            Controls.Add(lblTitle)
            Controls.Add(lbxBook)

End Sub

This would produce:

If you prefer to decide how much width should be allowed, then set the desired value in the HorizontalExtent property.

Practical Learning Practical Learning: Implementing List Boxes

  1. Display the form and click the most right list box. Using the Properties window, set its HorizontalScrollbar property to True
  2. Execute the application and process an order
  3. After using it, close the form and return to your programming environment

A Multi-Column List Box

When you create a list of items, they appear in one column. If the number of items exceeds the height, a scrollbar would appear on the control. An alternative you can use is to span the list to more than one column. To support this, the ListBox class is equipped with the MultiColumn Boolean property. At design time, you can set this characteristic in the Properties window. By default, the MultiColumn value is set to False, which means the items appear in one column. If you set this property to True, then the compiler would decide if or when the control needs the columns, based on the number of items in the list. You can then specify the width of each column using the ColumnWidth property.

A Custom Owner-Draw List Box

A list box is painted based on three types or style. This characteristic is controlled by the DrawMode property. When its value is set to Normal, the operating system would regularly draw each item of the list. If you want each item of the list to display a graphic or a color, you must set the style to an owner drawn type. The OwnerDrawFixed value allows you to set a desired but same height for each item of the list. This height is controlled through the ItemHeight property. You can set a different height for each item if you set the list style to OwnerDrawVariable.

Introduction to the Checked List Boxes

 

Description

A checked list box is a list box whose items are each equipped with a check box. In the following Customize dialog box of Microsoft Visual Studio, the control under the Toolbars label is a checked list box:

The Customize dialog box of Microsoft Office

A checked list box combines the functionalities of the list box and the check box controls. As a list box, it displays each of its items on a line. If there are too many items than the control can display, it would be equipped with a vertical scroll bar.

To select an item in the list, the user can click the desired string. The most important and obvious characteristic of the checked list box is that each item displays a check box on its left. This box allows the user to select or deselect each item. To select an item, the user must click its box and not its string, to indicate an explicit selection. This draws a check mark in the box. As described with the check box control, the user can deselect an item by removing the check mark. The check mark indicates that an item is selected and the absence of the check mark indicates the contrary. Like the check box control, you can allow the user to indicate a "half-checked" item. In this case, a check box can appear unchecked, checked, or grayed.

Practical Learning Practical Learning: Introducing Checked List Boxes

  1. Start a new Windows Application named AltairRealtors1
  2. On the main menu, click Project ->Add Class...
  3. Set the Name to AvailableProperty and click Add
  4. Change the file as follows:
     
    Public Class AvailableProperty
        Private propNbr As Long
        Private propType As String
        Private adrs As String
        Private ct As String
        Private stt As String
        Private zip As Integer
        Private beds As Byte
        Private baths As Single
        Private mValue As Double
    
        Public Property PropertyNumber() As Long
            Get
                Return propNbr
            End Get
            Set(ByVal value As Long)
                propNbr = value
            End Set
        End Property
    
        Public Property PropertyType() As String
            Get
                Return propType
            End Get
            Set(ByVal value As String)
                propType = value
            End Set
        End Property
    
        Public Property Address() As String
            Get
                Return adrs
            End Get
            Set(ByVal value As String)
                adrs = value
            End Set
        End Property
    
        Public Property City() As String
            Get
                Return ct
            End Get
            Set(ByVal value As String)
                ct = value
            End Set
        End Property
    
        Public Property State() As String
            Get
                Return stt
            End Get
            Set(ByVal value As String)
                stt = value
            End Set
        End Property
    
        Public Property ZIPCode() As Integer
            Get
                Return zip
            End Get
            Set(ByVal value As Integer)
                zip = value
            End Set
        End Property
    
        Public Property Bedrooms() As Byte
            Get
                Return beds
            End Get
            Set(ByVal value As Byte)
                beds = value
            End Set
        End Property
    
        Public Property Bathrooms() As Single
            Get
                Return baths
            End Get
            Set(ByVal value As Single)
                baths = value
            End Set
        End Property
    
        Public Property MarketValue() As Double
            Get
                Return mValue
            End Get
            Set(ByVal value As Double)
                mValue = value
            End Set
        End Property
    
        Public Sub New()
    
        End Sub
    
        Public Sub New(ByVal code As Long, ByVal type As String, _
                           ByVal addrs As String, ByVal cty As String, _
                           ByVal states As String, ByVal zCode As Integer, _
                           ByVal bedroom As Byte, ByVal bathroom As Single, _
                           ByVal value As Double)
            propNbr = code
            propType = type
            adrs = Address
            ct = City
            stt = State
            zip = zCode
            beds = bedroom
            baths = bathroom
            mValue = value
        End Sub
    
    End Class
  5. In the Solution Explorer, right-click Form1.vb and click Rename
  6. Type RealEstate.vb and press Enter twice

Creating a Checked List Box

To support checked list boxes, the .NET Framework provides the CheckedListBox class. At design time, to add a checked list box to your application, from the Common Controls section of the Toolbox, click the CheckedListBox button CheckedListBox and click the form or the container that would host the control. To programmatically create a checked list box, declare a variable of type CheckedListBox, use the new operator to allocate memory for it, and add it to the Controls collection of its parent. Here is an example:

Imports System.Drawing
Imports System.Windows.Forms

Module Exercise

    Public Class Starter
        Inherits Form

        private lbxPersonalRelationships as   CheckedListBox

        Dim components As System.ComponentModel.Container

        Public Sub New()
            InitializeComponent()
        End Sub

        Public Sub InitializeComponent()

            lbxPersonalRelationships = New CheckedListBox()
            lbxPersonalRelationships.Location = New Point(12, 12)

            Controls.Add(lbxPersonalRelationships)

        End Sub

    End Class

    Function Main() As Integer

        Dim frmStart As Starter = New Starter

        Application.Run(frmStart)

        Return 0
    End Function

End Module

This would produce:

Practical Learning Practical Learning: Creating Checked List Boxes

  1. Design the form as follows:
     
    Altair Realtors
     
    Control Text Name Other Properties
    Label Label Altair Realtors   BorderStyle: FixedSingle
    Font: Times New Roman, 21.75pt, style=Bold
    AutoSize: False
    TextAlign: MiddleCenter
    Label Label Types to Show    
    CheckedListBox   lbxPropertiesTypes  
    Button Show btnShow  
    Label Label Properties_______   Font: Garamond, 15.75pt, style=Bold
    Label Label Prop #    
    Label Label Address    
    Label Label City    
    Label Label State    
    Label Label ZIP Code    
    Label Label Beds    
    Label Label Baths    
    Label Label Market Value    
    ListBox ListBox   lbxPropertyNumbers  
    ListBox ListBox   lbxAddresses  
    ListBox ListBox   lbxCities  
    ListBox ListBox   lbxStates  
    ListBox ListBox   lbxZIPCodes  
    ListBox ListBox   lbxBedrooms  
    ListBox ListBox   lbxBathrooms  
    ListBox ListBox   lbxMarketValues  
    Button Button Close btnClose  
  2. Save the form

Characteristics of a Checked List Box

 

Introduction

The CheckedListBox class is derived from the ListBox class. This means that the checked list box possesses all the public (and protected) characteristics of the list box and its parent the ListControl class. This control also uses the HorizontalScrollbar and the HorizontalExtent properties that behave exactly as we reviewed for the list box. It also uses the SelectionMode property with the same behavior as that of the list box.

Creating the List of Items

As seen for the list box, the primary aspect of a checked list box is its list of items. At design time, to create the list of items of a checked list box, access its Properties window, and click the ellipsis button to open the String Collection Editor. Type each item followed by a carriage return. After creating the list, click OK. To programmatically create the list of items, access the Items property. The list is created from the nested ObjectCollection class that implements the IList, the ICollection, and the IEnumerable interfaces. This means that the CheckedListBox.ObjectCollection class behaves the same as the ListBox.ObjectCollection class. Here is an example:

Public Sub InitializeComponent()

            lbxPersonalRelationships = New CheckedListBox()
            lbxPersonalRelationships.Location = New Point(12, 12)

            lbxPersonalRelationships.Items.Add("Family Member")
            lbxPersonalRelationships.Items.Add("Friend")
            lbxPersonalRelationships.Items.Add("Classmate")
            lbxPersonalRelationships.Items.Add("Business Partner")
            lbxPersonalRelationships.Items.Add("Simple Acquaintance")
            lbxPersonalRelationships.Items.Add("Undefined")

            Controls.Add(lbxPersonalRelationships)

End Sub

This would produce:

Remember that you can also add an array of items by calling the AddRange() and you can insert an item using the Insert() method.

Practical Learning Practical Learning: Creating a List of Items

  1. On the form, click the checked list box
  2. In the Properties window, click Items and click its ellipsis button
  3. In the String Collection Editor, type Single Families and press Enter
  4. Type Townhouses and press Enter
  5. Type Condominiums and press Enter
  6. Type Trailers and click OK

Checking an Item

As mentioned already, the main difference between a list box and a checked list is the presence of check marks in the former. When using the control, the user can click one or more check boxes. Here is an example:

After the user has clicked a few check boxes, you may want to find out which ones are checked. The checked list box provides two techniques you can use.

As seen for the list box, each item of the control has an index. When one, a few, or all items have been checked (those that display a check mark), the indices of the checked items are stored in a collection represented by the CheckedIndices property. This property is based on the nested CheckedIndexCollection collection class. The CheckedIndexCollection class implements the IList, the ICollection, and the IEnumerable interfaces.

The identifications of the checked items are stored in a collection represented by the CheckedItems property. This property is based on the nested CheckedItemCollection class. The CheckedItemCollection class implements the IList, the ICollection, and the IEnumerable interfaces. This implies that you can use it to get the number of selected items.

When the user has clicked item to put a check mark on it, the control fires the ItemCheck event.

As you can see, the event is carried by the ItemCheckEventArgs class.

One of the most important operations to perform on a list of selected items is to find out whether a particular item is checked. To get this information, the CheckedItemCollection class provides a method named Contains. Its syntax is:

Public Function Contains(item As Object) As Boolean

This method takes as argument a value that can identify an item from the checked list box. If the item is found and it is checked, this method returns true. Otherwise, it returns false. 

Practical Learning Practical Learning: Using the List of Checked Items

  1. Double-click an unoccupied area of the form to generate its Load event
  2. Change the file as follows:
     
    Public Class RealEstate
        Private Properties(14) As AvailableProperty
    
        Private Sub RealEstate_Load(ByVal sender As System.Object, _
                                    ByVal e As System.EventArgs) _
                                    Handles MyBase.Load
            Properties(0) = New AvailableProperty()
            Properties(0).PropertyNumber = 602138
            Properties(0).PropertyType = "Single Family"
            Properties(0).Address = "11604 Aldora Avenue"
            Properties(0).City = "Baltimore"
            Properties(0).State = "MD"
            Properties(0).ZIPCode = 21205
            Properties(0).Bedrooms = 5
            Properties(0).Bathrooms = 3.5F
            Properties(0).MarketValue = 265880
    
            Properties(1) = New AvailableProperty()
            Properties(1).PropertyNumber = 749562
            Properties(1).PropertyType = "Townhouse"
            Properties(1).Address = "495 Parker House Terrace"
            Properties(1).City = "Gettysburg"
            Properties(1).State = "WV"
            Properties(1).ZIPCode = 26201
            Properties(1).Bedrooms = 3
            Properties(1).Bathrooms = 2.5F
            Properties(1).MarketValue = 225500
    
            Properties(2) = New AvailableProperty()
            Properties(2).PropertyNumber = 304750
            Properties(2).PropertyType = "Condominium"
            Properties(2).Address = "5900 24th Street NW #812"
            Properties(2).City = "Washington"
            Properties(2).State = "DC"
            Properties(2).ZIPCode = 20008
            Properties(2).Bedrooms = 1
            Properties(2).Bathrooms = 1.0F
            Properties(2).MarketValue = 388665
    
            Properties(3) = New AvailableProperty()
            Properties(3).PropertyNumber = 682630
            Properties(3).PropertyType = "Single Family"
            Properties(3).Address = "6114 Costinna Avenue"
            Properties(3).City = "Martinsburg"
            Properties(3).State = "WV"
            Properties(3).ZIPCode = 25401
            Properties(3).Bedrooms = 4
            Properties(3).Bathrooms = 3.5F
            Properties(3).MarketValue = 325000
    
            Properties(4) = New AvailableProperty()
            Properties(4).PropertyNumber = 480750
            Properties(4).PropertyType = "Condominium"
            Properties(4).Address = "10710 Desprello Street #10D"
            Properties(4).City = "Rockville"
            Properties(4).State = "MD"
            Properties(4).ZIPCode = 20856
            Properties(4).Bedrooms = 1
            Properties(4).Bathrooms = 1.0F
            Properties(4).MarketValue = 528445
    
            Properties(5) = New AvailableProperty()
            Properties(5).PropertyNumber = 209475
            Properties(5).PropertyType = "Single Family"
            Properties(5).Address = "519D Estuardo Way"
            Properties(5).City = "Silver Spring"
            Properties(5).State = "MD"
            Properties(5).ZIPCode = 20906
            Properties(5).Bedrooms = 2
            Properties(5).Bathrooms = 1.0F
            Properties(5).MarketValue = 325995
    
            Properties(6) = New AvailableProperty()
            Properties(6).PropertyNumber = 304185
            Properties(6).PropertyType = "Townhouse"
            Properties(6).Address = "10116 Lottsford Drive"
            Properties(6).City = "Takoma Park"
            Properties(6).State = "MD"
            Properties(6).ZIPCode = 20910
            Properties(6).Bedrooms = 4
            Properties(6).Bathrooms = 3.5F
            Properties(6).MarketValue = 450500
    
            Properties(7) = New AvailableProperty()
            Properties(7).PropertyNumber = 93857
            Properties(7).PropertyType = "Single Family"
            Properties(7).Address = "9047 Woodyard Road"
            Properties(7).City = "York"
            Properties(7).State = "PA"
            Properties(7).ZIPCode = 17405
            Properties(7).Bedrooms = 4
            Properties(7).Bathrooms = 2.5F
            Properties(7).MarketValue = 326885
    
            Properties(8) = New AvailableProperty()
            Properties(8).PropertyNumber = 930755
            Properties(8).PropertyType = "Condominium"
            Properties(8).Address = "3842 Accolade Avenue #1206"
            Properties(8).City = "Alexandria"
            Properties(8).State = "VA"
            Properties(8).ZIPCode = 22231
            Properties(8).Bedrooms = 3
            Properties(8).Bathrooms = 2.0F
            Properties(8).MarketValue = 525885
    
            Properties(9) = New AvailableProperty()
            Properties(9).PropertyNumber = 240875
            Properties(9).PropertyType = "Townhouse"
            Properties(9).Address = "842 Hempton Street"
            Properties(9).City = "Charlestown"
            Properties(9).State = "WV"
            Properties(9).ZIPCode = 25414
            Properties(9).Bedrooms = 3
            Properties(9).Bathrooms = 2.5F
            Properties(9).MarketValue = 212500
    
            Properties(10) = New AvailableProperty()
            Properties(10).PropertyNumber = 940075
            Properties(10).PropertyType = "Single Family"
            Properties(10).Address = "4813 Woodland Court"
            Properties(10).City = "Falls Church"
            Properties(10).State = "VA"
            Properties(10).ZIPCode = 22042
            Properties(10).Bedrooms = 5
            Properties(10).Bathrooms = 3.5F
            Properties(10).MarketValue = 645860
    
            Properties(11) = New AvailableProperty()
            Properties(11).PropertyNumber = 931475
            Properties(11).PropertyType = "Townhouse"
            Properties(11).Address = "5030 Goodson Road"
            Properties(11).City = "Arlington"
            Properties(11).State = "VA"
            Properties(11).ZIPCode = 22203
            Properties(11).Bedrooms = 4
            Properties(11).Bathrooms = 3.5F
            Properties(11).MarketValue = 435775
    
            Properties(12) = New AvailableProperty()
            Properties(12).PropertyNumber = 248095
            Properties(12).PropertyType = "Condominium"
            Properties(12).Address = "9182 Weston Ave NW #F14"
            Properties(12).City = "Washington"
            Properties(12).State = "DC"
            Properties(12).ZIPCode = 20016
            Properties(12).Bedrooms = 2
            Properties(12).Bathrooms = 1.0F
            Properties(12).MarketValue = 425665
    
            Properties(13) = New AvailableProperty()
            Properties(13).PropertyNumber = 293705
            Properties(13).PropertyType = "Single Family"
            Properties(13).Address = "12404 Livingston Boulevard"
            Properties(13).City = "Martinsburg"
            Properties(13).State = "WV"
            Properties(13).ZIPCode = 25401
            Properties(13).Bedrooms = 4
            Properties(13).Bathrooms = 2.5F
            Properties(13).MarketValue = 225660
    
            Properties(14) = New AvailableProperty()
            Properties(14).PropertyNumber = 937905
            Properties(14).PropertyType = "Condominium"
            Properties(14).Address = "2039 Gonnard Road E5"
            Properties(14).City = "Laurel"
            Properties(14).State = "MD"
            Properties(14).ZIPCode = 20747
            Properties(14).Bedrooms = 2
            Properties(14).Bathrooms = 2
            Properties(14).MarketValue = 275880
        End Sub
    End Class
  3. In the Class Name combo box, select btnShow
  4. In the Method Name combo box, select Click and implement the event as follows:
     
    Private Sub btnShow_Click(ByVal sender As Object, _
                                  ByVal e As System.EventArgs) _
                                  Handles btnShow.Click
            lbxPropertyNumbers.Items.Clear()
            lbxAddresses.Items.Clear()
            lbxCities.Items.Clear()
            lbxStates.Items.Clear()
            lbxZIPCodes.Items.Clear()
            lbxBedrooms.Items.Clear()
            lbxBathrooms.Items.Clear()
            lbxMarketValues.Items.Clear()
    
            If lbxPropertiesTypes.CheckedItems.Contains("Single Families") Then
                For Each prop As AvailableProperty In Properties
                    If prop.PropertyType = "Single Family" Then
                        lbxPropertyNumbers.Items.Add(CStr(prop.PropertyNumber))
                        lbxAddresses.Items.Add(prop.Address)
                        lbxCities.Items.Add(prop.City)
                        lbxStates.Items.Add(prop.State)
                        lbxZIPCodes.Items.Add(prop.ZIPCode)
                        lbxBedrooms.Items.Add(prop.Bedrooms)
                        lbxBathrooms.Items.Add(prop.Bathrooms)
                        lbxMarketValues.Items.Add(prop.MarketValue)
                    End If
                Next
            End If
    
            If lbxPropertiesTypes.CheckedItems.Contains("Townhouses") Then
                For Each prop As AvailableProperty In Properties
                    If prop.PropertyType = "Townhouse" Then
                        lbxPropertyNumbers.Items.Add(prop.PropertyNumber.ToString())
                        lbxAddresses.Items.Add(prop.Address)
                        lbxCities.Items.Add(prop.City)
                        lbxStates.Items.Add(prop.State)
                        lbxZIPCodes.Items.Add(prop.ZIPCode)
                        lbxBedrooms.Items.Add(prop.Bedrooms)
                        lbxBathrooms.Items.Add(prop.Bathrooms)
                        lbxMarketValues.Items.Add(prop.MarketValue)
                    End If
                Next
            End If
    
            If lbxPropertiesTypes.CheckedItems.Contains("Condominiums") Then
                For Each prop As AvailableProperty In Properties
                    If prop.PropertyType = "Condominium" Then
                        lbxPropertyNumbers.Items.Add(prop.PropertyNumber.ToString())
                        lbxAddresses.Items.Add(prop.Address)
                        lbxCities.Items.Add(prop.City)
                        lbxStates.Items.Add(prop.State)
                        lbxZIPCodes.Items.Add(prop.ZIPCode)
                        lbxBedrooms.Items.Add(prop.Bedrooms)
                        lbxBathrooms.Items.Add(prop.Bathrooms)
                        lbxMarketValues.Items.Add(prop.MarketValue)
                    End If
                Next
            End If
    End Sub
  5. In the Class Name combo box, select btnClose
  6. In the Method Name combo box, select Click and implement the event as follows:
     
    Private Sub btnClose_Click(ByVal sender As Object, _
                                   ByVal e As System.EventArgs) _
                                   Handles btnClose.Click
            End
    End Sub
  7. Execute the application and test the checked list box
     
  8. Close the form and return to your programming environment

Automatically Checking an Item When Clicked

From its default implementation, when a checked list box is presented to the user, when an item is clicked, its string gets highlighted but no check mark is put in the box. To put a check mark on the item, the user must click it again. This is not an anomaly. It is purposely so the user would know the difference between an item that is selected and one that is checked.

To support the ability to automatically put a check mark on an item when the user clicks it, the CheckedListBox provides the CheckOnClick Boolean property. Its default value is False. If you want the items to be automatically checked, set this property to true.

On an existing checked list box, to find out if the its items are automatically checked, get the value of the CheckOnClick property.

Practical Learning Practical Learning: Automatically Checking an Item

  1. On the form, click the checked list box
  2. In the Properties window, double-click CheckOnClick to set its value to True
  3. Save the form

3-D Checked Items

After creating the list, each item appears with a flat check box to its left. If you want a 3-D check box, you can change the Boolean ThreeDCheckBoxes property from its False default to a True value:

ThreeDCheckBoxes 
False True 
Checked List Box: Travel Planning
 

Previous Copyright © 2008-2009, yevol.com Next