Microsoft KB Archive/820632

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

Article ID: 820632

Article Last Modified on 5/11/2007

-

APPLIES TO


 * Microsoft Visual Studio .NET 2003 Enterprise Architect
 * Microsoft Visual Studio .NET 2003 Enterprise Developer
 * 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
 * Microsoft Visual Studio .NET 2002 Enterprise Developer
 * 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 &quot;Applies to&quot; section.



Steps to Reproduce the Behavior
 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. Right-click Form1, and then click View Code.  Replace the existing code with the following code:

Visual Basic .NET or Visual Basic 2005 Code Public Class Form1 Inherits System.Windows.Forms.Form

Public Sub New MyBase.New 'This call is required by the Windows Form Designer. InitializeComponent 'Add any initialization after the InitializeComponent call. End Sub
 * 1) Region &quot; Windows Form Designer generated code &quot;

'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  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 {&quot;item&quot; & Microsoft.VisualBasic.ChrW(9) & &quot;1&quot; & Microsoft.VisualBasic.ChrW(9) & &quot;9&quot; & Microsoft.VisualBasic.ChrW(9) & &quot;15&quot;, &quot;item&quot; & Microsoft.VisualBasic.ChrW(9) & &quot;2&quot; & Microsoft.VisualBasic.ChrW(9) & &quot;10&quot; & Microsoft.VisualBasic.ChrW(9) & &quot;16&quot;, &quot;item&quot; & Microsoft.VisualBasic.ChrW(9) & &quot;3&quot; & Microsoft.VisualBasic.ChrW(9) & &quot;11&quot; & Microsoft.VisualBasic.ChrW(9) & &quot;17&quot;}) Me.ListBox1.Location = New System.Drawing.Point(16, 72) Me.ListBox1.Name = &quot;ListBox1&quot; Me.ListBox1.Size = New System.Drawing.Size(120, 95) Me.ListBox1.TabIndex = 0 '       'CheckedListBox1 '       Me.CheckedListBox1.Items.AddRange(New Object {&quot;item&quot; & Microsoft.VisualBasic.ChrW(9) & &quot;1&quot; & Microsoft.VisualBasic.ChrW(9) & &quot;9&quot; & Microsoft.VisualBasic.ChrW(9) & &quot;15&quot;, &quot;item&quot; & Microsoft.VisualBasic.ChrW(9) & &quot;2&quot; & Microsoft.VisualBasic.ChrW(9) & &quot;10&quot; & Microsoft.VisualBasic.ChrW(9) & &quot;16&quot;, &quot;item&quot; & Microsoft.VisualBasic.ChrW(9) & &quot;3&quot; & Microsoft.VisualBasic.ChrW(9) & &quot;11&quot; & Microsoft.VisualBasic.ChrW(9) & &quot;17&quot;}) Me.CheckedListBox1.Location = New System.Drawing.Point(168, 72) Me.CheckedListBox1.Name = &quot;CheckedListBox1&quot; 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 = &quot;Form1&quot; Me.Text = &quot;Form1&quot; Me.ResumeLayout(False)

End Sub

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.
 * 1) End Region

For more information about the new Visual Basic 2005 language enhancements, visit the following Microsoft Developer Network (MSDN) Web site:

http://msdn2.microsoft.com/en-us/library/ms379584(vs.80).aspx

For more information about partial classes and the Windows Forms Designer, visit the following MSDN Web site:

http://msdn2.microsoft.com/en-us/library/ms171843.aspx

Visual C# .NET Code public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.CheckedListBox checkedListBox1; private System.Windows.Forms.ListBox listBox1; ///        /// Required designer variable. ///        private System.ComponentModel.Container components = null;

public Form1 {           //            // Required for Windows Form Designer support. //           InitializeComponent;

//           // TODO: Add any constructor code after InitializeComponent call. //       }

///        /// Clean up any resources that are being used. ///        protected override void Dispose( bool disposing ) {           if( disposing ) {               if (components != null) {                   components.Dispose; }           }            base.Dispose( disposing ); }

#region Windows Form Designer generated code ///        /// Required method for Designer support - do not modify /// the contents of this method with the Code editor. ///        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[] {                                                                 &quot;item\t1\t9\t15&quot;,                                                                 &quot;item\t2\t10\t16&quot;,                                                                 &quot;item\t3\t11\t17&quot;}); this.checkedListBox1.Location = new System.Drawing.Point(152, 40); this.checkedListBox1.Name = &quot;checkedListBox1&quot;; this.checkedListBox1.Size = new System.Drawing.Size(120, 94); this.checkedListBox1.TabIndex = 0; //            // listBox1 //            this.listBox1.Items.AddRange(new object[] {                                                          &quot;item\t1\t9\t15&quot;,                                                          &quot;item\t2\t10\t16&quot;,                                                          &quot;item\t3\t11\t17&quot;}); this.listBox1.Location = new System.Drawing.Point(16, 40); this.listBox1.Name = &quot;listBox1&quot;; 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 = &quot;Form1&quot;; this.Text = &quot;Form1&quot;; this.Load += new System.EventHandler(this.Form1_Load); this.ResumeLayout(false);

}       #endregion

///        /// The main entry point for the application. ///        [STAThread] static void Main {           Application.Run(new Form1); }

}  In Solution Explorer, right-click Form1, and then click View Designer.

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

Notice the first item in CheckedListBox1.</ol>

<div class="references_section">