BUG: The first line in the list does not display correctly if the items in the CheckedListBox control contain multiple TAB characters (820632)



The information in this article applies to:

  • Microsoft Visual Studio .NET (2003), Enterprise Architect Edition
  • Microsoft Visual Studio .NET (2003), Enterprise Developer Edition
  • Microsoft Visual Studio .NET (2003), Professional Edition
  • Microsoft Visual Studio .NET (2003), Academic Edition
  • Microsoft Visual Studio .NET (2002), Academic Edition
  • Microsoft Visual Studio .NET (2002), Enterprise Architect Edition
  • Microsoft Visual Studio .NET (2002), Enterprise Developer Edition
  • Microsoft Visual Studio .NET (2002), Professional Edition
  • Microsoft Visual Basic 2005

SYMPTOMS

When you use the CheckedListBox control, and the items in the control contain multiple TAB characters, the first line in the list does not display correctly. This behavior may occur during design time and during run time.

WORKAROUND

To work around this bug, increase or decrease the width of the CheckedListBox control. Typically, you solve the problem if you increase the width of the CheckedListBox control. However, you may not always solve the problem if you decrease the width of the CheckedListBox control. This is based on the column width of the CheckedListBox control.

STATUS

Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Create a new Windows application by using Microsoft Visual Basic .NET or Microsoft Visual Basic 2005 or Microsoft Visual C# .NET.

    By default, Form1 is created.
  2. Right-click Form1, and then click View Code.
  3. Replace the existing code with the following code:

    Visual Basic .NET or Visual Basic 2005 Code
    Public Class Form1
        Inherits System.Windows.Forms.Form
    
    #Region " Windows Form Designer generated code "
        Public Sub New()
            MyBase.New()
            'This call is required by the Windows Form Designer.
            InitializeComponent()
            'Add any initialization after the InitializeComponent() call.
        End Sub
    
        'Form overrides dispose to clean up the component list.
        Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
            If disposing Then
                If Not (components Is Nothing) Then
                    components.Dispose()
                End If
            End If
            MyBase.Dispose(disposing)
        End Sub
    
        'Required by the Windows Form Designer.
        Private components As System.ComponentModel.IContainer
    
        'NOTE: The following procedure is required by the Windows Form Designer.
        'It can be modified by using the Windows Form Designer.  
        'Do not modify it by using the Code editor.
        Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
        Friend WithEvents CheckedListBox1 As System.Windows.Forms.CheckedListBox
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
            Me.ListBox1 = New System.Windows.Forms.ListBox
            Me.CheckedListBox1 = New System.Windows.Forms.CheckedListBox
            Me.SuspendLayout()
            '
            'ListBox1
            '
            Me.ListBox1.Items.AddRange(New Object() {"item" & Microsoft.VisualBasic.ChrW(9) & "1" & Microsoft.VisualBasic.ChrW(9) & "9" & Microsoft.VisualBasic.ChrW(9) & "15", "item" & Microsoft.VisualBasic.ChrW(9) & "2" & Microsoft.VisualBasic.ChrW(9) & "10" & Microsoft.VisualBasic.ChrW(9) & "16", "item" & Microsoft.VisualBasic.ChrW(9) & "3" & Microsoft.VisualBasic.ChrW(9) & "11" & Microsoft.VisualBasic.ChrW(9) & "17"})
            Me.ListBox1.Location = New System.Drawing.Point(16, 72)
            Me.ListBox1.Name = "ListBox1"
            Me.ListBox1.Size = New System.Drawing.Size(120, 95)
            Me.ListBox1.TabIndex = 0
            '
            'CheckedListBox1
            '
            Me.CheckedListBox1.Items.AddRange(New Object() {"item" & Microsoft.VisualBasic.ChrW(9) & "1" & Microsoft.VisualBasic.ChrW(9) & "9" & Microsoft.VisualBasic.ChrW(9) & "15", "item" & Microsoft.VisualBasic.ChrW(9) & "2" & Microsoft.VisualBasic.ChrW(9) & "10" & Microsoft.VisualBasic.ChrW(9) & "16", "item" & Microsoft.VisualBasic.ChrW(9) & "3" & Microsoft.VisualBasic.ChrW(9) & "11" & Microsoft.VisualBasic.ChrW(9) & "17"})
            Me.CheckedListBox1.Location = New System.Drawing.Point(168, 72)
            Me.CheckedListBox1.Name = "CheckedListBox1"
            Me.CheckedListBox1.Size = New System.Drawing.Size(120, 94)
            Me.CheckedListBox1.TabIndex = 1
            '
            'Form1
            '
            Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
            Me.ClientSize = New System.Drawing.Size(352, 266)
            Me.Controls.Add(Me.CheckedListBox1)
            Me.Controls.Add(Me.ListBox1)
            Me.Name = "Form1"
            Me.Text = "Form1"
            Me.ResumeLayout(False)
    
        End Sub
    
    #End Region
        
    End Class
    
    Note You must change the code in Visual Basic 2005. By default, Visual Basic creates two files for the project when you create a Windows Forms project. If the form is named Form1, the two files that represent the form are named Form1.vb and Form1.Designer.vb. You write the code in the Form1.vb file. The Windows Forms Designer writes the code in the Form1.Designer.vb file. The Windows Forms Designer uses the partial keyword to divide the implementation of Form1 into two separate files. This behavior prevents the designer-generated code from being interspersed with your code.

    For more information about the new Visual Basic 2005 language enhancements, visit the following Microsoft Developer Network (MSDN) Web site: For more information about partial classes and the Windows Forms Designer, visit the following MSDN Web site:
    Visual C# .NET Code
    public class Form1 : System.Windows.Forms.Form
    	{
    private System.Windows.Forms.CheckedListBox checkedListBox1;
    		private System.Windows.Forms.ListBox listBox1;
    		/// <summary>
    		/// Required designer variable.
    		/// </summary>
    		private System.ComponentModel.Container components = null;
    
    		public Form1()
    		{
    			//
    			// Required for Windows Form Designer support.
    			//
    			InitializeComponent();
    
    			//
    			// TODO: Add any constructor code after InitializeComponent call.
    			//
    		}
    
    		/// <summary>
    		/// Clean up any resources that are being used.
    		/// </summary>
    		protected override void Dispose( bool disposing )
    		{
    			if( disposing )
    			{
    				if (components != null) 
    				{
    					components.Dispose();
    				}
    			}
    			base.Dispose( disposing );
    		}
    
    		#region Windows Form Designer generated code
    		/// <summary>
    		/// Required method for Designer support - do not modify
    		/// the contents of this method with the Code editor.
    		/// </summary>
    		private void InitializeComponent()
    		{
    			this.checkedListBox1 = new System.Windows.Forms.CheckedListBox();
    			this.listBox1 = new System.Windows.Forms.ListBox();
    			this.SuspendLayout();
    			// 
    			// checkedListBox1
    			// 
    			this.checkedListBox1.Items.AddRange(new object[] {
    																 "item\t1\t9\t15",
    																 "item\t2\t10\t16",
    																 "item\t3\t11\t17"});
    			this.checkedListBox1.Location = new System.Drawing.Point(152, 40);
    			this.checkedListBox1.Name = "checkedListBox1";
    			this.checkedListBox1.Size = new System.Drawing.Size(120, 94);
    			this.checkedListBox1.TabIndex = 0;
    			// 
    			// listBox1
    			// 
    			this.listBox1.Items.AddRange(new object[] {
    														  "item\t1\t9\t15",
    														  "item\t2\t10\t16",
    														  "item\t3\t11\t17"});
    			this.listBox1.Location = new System.Drawing.Point(16, 40);
    			this.listBox1.Name = "listBox1";
    			this.listBox1.Size = new System.Drawing.Size(120, 95);
    			this.listBox1.TabIndex = 1;
    			// 
    			// Form1
    			// 
    			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
    			this.ClientSize = new System.Drawing.Size(292, 182);
    			this.Controls.Add(this.listBox1);
    			this.Controls.Add(this.checkedListBox1);
    			this.Name = "Form1";
    			this.Text = "Form1";
    			this.Load += new System.EventHandler(this.Form1_Load);
    			this.ResumeLayout(false);
    
    		}
    		#endregion
    
    		/// <summary>
    		/// The main entry point for the application.
    		/// </summary>
    		[STAThread]
    		static void Main() 
    		{
    			Application.Run(new Form1());
    		}
    
    }
  4. In Solution Explorer, right-click Form1, and then click View Designer.

    In the Form1 Design view, notice the first item in CheckedListBox1.
  5. On the Debug menu, click Start to run the application.

    Notice the first item in CheckedListBox1.

REFERENCES

For more information, click the following article number to view the article in the Microsoft Knowledge Base:

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


Modification Type:MinorLast Reviewed:10/3/2006
Keywords:kbvs2005swept kbvs2005applies kbvs2002sp1sweep KbUIDesign kbWindowsForms kbListBox kbControl kbbug KB820632 kbAudDeveloper