Microsoft KB Archive/327896

= BUG: CheckedListBox Control Loses Check Marks When the Visible Property Is Changed to FALSE and Then Back to TRUE =

Article ID: 327896

Article Last Modified on 9/4/2003

-

APPLIES TO


 * Microsoft Common Language Runtime (included with the .NET Framework) 1.0

-



This article was previously published under Q327896



SYMPTOMS
Check marks are cleared when the visibility of a CheckedListBox control changes. This only occurs when the control is data-bound.



CAUSE
This problem occurs because the CheckedListBox was not designed for data binding.



RESOLUTION
You can populate the CheckedListBox manually. You must not use data binding with the CheckedListBox. Dim DataTbl As New DataTable(&quot;DemoTable&quot;) Dim DataCol1 As New DataColumn Dim DRow As DataRow Dim counter As Int32

DataCol1.DataType = GetType(String) DataCol1.ColumnName = &quot;Name&quot; DataTbl.Columns.Add(DataCol1)

For counter = 0 To 10 DRow = DataTbl.NewRow DRow(&quot;Name&quot;) = &quot;John &quot; & counter.ToString DataTbl.Rows.Add(DRow) Next

Dim sqlDS As New DataSet sqlDS.Tables.Add(DataTbl)

For Each DRow In sqlDS.Tables(&quot;DemoTable&quot;).Rows Me.CheckedListBox1.Items.Add(DRow(&quot;Name&quot;)) Next



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce the Behavior
 Create a new Windows Application. Add a TabControl control to the Form. Add two TabPage controls to the TabControl. Add CheckedListBox to one of the TabPage controls.  Double-click the Form and then add the following code to the Forms Load event: Dim DataTbl As New DataTable(&quot;DemoTable&quot;) Dim DataCol1 As New DataColumn Dim DataCol2 As New DataColumn Dim DRow As DataRow Dim counter As Int32

DataCol1.DataType = GetType(Int32) DataCol1.ColumnName = &quot;ID&quot; DataCol1.AutoIncrement = True DataTbl.Columns.Add(DataCol1) Dim Key(0) As DataColumn Key(0) = DataCol1 DataTbl.PrimaryKey = Key

DataCol2.DataType = GetType(String) DataCol2.ColumnName = &quot;Name&quot; DataTbl.Columns.Add(DataCol2)

For counter = 0 To 10 DRow = DataTbl.NewRow DRow(&quot;Name&quot;) = &quot;John &quot; & counter.ToString DataTbl.Rows.Add(DRow) Next

Dim sqlDS As New DataSet sqlDS.Tables.Add(DataTbl)

With CheckedListBox1 .DataSource = sqlDS.Tables(&quot;DemoTable&quot;) .ValueMember = &quot;ID&quot; .DisplayMember = &quot;Name&quot; End With </li> Press F5 to compile and to run the application.</li> Check items on the CheckedListBox.</li> Toggle between one TabPage and the other TabPage.

Notice that when you return to the TabPage that contains the CheckedListBox control, all check marks on the control are cleared.</li></ol>

Keywords: kbbug KB327896

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.