Export (0) Print
Expand All

ListBox.ColumnWidth Property

Gets or sets the width of columns in a multicolumn ListBox.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

'Declaration
Public Property ColumnWidth As Integer

Property Value

Type: System.Int32
The width, in pixels, of each column in the control. The default is 0.

ExceptionCondition
ArgumentException

A value less than zero is assigned to the property.

If you set the value to zero (0), a default width is assigned to each column. If the ListBox is a multicolumn ListBox, this property returns the current width of each column in the list. You can use this property to ensure that each column in a multicolumn ListBox can properly display its items.

The following code example demonstrates a simple two-column ListBox.

Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms

Public Class Form1
   Inherits Form
   Private listBox1 As ListBox


   Public Sub New()
      InitializeComponent()
   End Sub

   <STAThread()>  _
   Shared Sub Main()
      Application.EnableVisualStyles()
      Application.SetCompatibleTextRenderingDefault(False)
      Application.Run(New Form1())
   End Sub 

   Private Sub InitializeComponent()
      Me.listBox1 = New System.Windows.Forms.ListBox()
      Me.SuspendLayout()
      '  
      ' listBox1 
      '  
      Me.listBox1.FormattingEnabled = True 
      Me.listBox1.HorizontalScrollbar = True 
      Me.listBox1.Items.AddRange(New Object() {"Item 1, column 1", "Item 2, column 1", "Item 3, column 1", "Item 4, column 1", "Item 5, column 1", "Item 1, column 2", "Item 2, column 2", "Item 3, column 2"})
      Me.listBox1.Location = New System.Drawing.Point(0, 0)
      Me.listBox1.MultiColumn = True 
      Me.listBox1.Name = "listBox1" 
      Me.listBox1.ScrollAlwaysVisible = True 
      Me.listBox1.Size = New System.Drawing.Size(120, 95)
      Me.listBox1.TabIndex = 0
      Me.listBox1.ColumnWidth = 85
      '  
      ' Form1 
      '  
      Me.ClientSize = New System.Drawing.Size(292, 273)
      Me.Controls.Add(listBox1)
      Me.Name = "Form1" 
      Me.ResumeLayout(False)
   End Sub 
End Class

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft