Export (0) Print
Expand All

ListBox.MultiColumn Property

Gets or sets a value indicating whether the ListBox supports multiple columns.

[Visual Basic]
Public Property MultiColumn As Boolean
[C#]
public bool MultiColumn {get; set;}
[C++]
public: __property bool get_MultiColumn();
public: __property void set_MultiColumn(bool);
[JScript]
public function get MultiColumn() : Boolean;
public function set MultiColumn(Boolean);

Property Value

true if the list box supports multiple columns; otherwise, false. The default is false.

Exceptions

Exception Type Condition
ArgumentException A multicolumn ListBox cannot have a variable-sized height.

Remarks

A multicolumn list box places items into as many columns as are needed to make vertical scrolling unnecessary. The user can use the keyboard to navigate to columns that are not currently visible. Set the HorizontalScrollbar property to true to display a horizontal scroll bar that allows the user to scroll to columns that are not currently shown in the visible region of the ListBox. The value of the ColumnWidth property determines the width of each column.

Example

[Visual Basic, C#, C++] The following example demonstrates how to use the ColumnWidth and MultiColumn properties to create a ListBox control that displays items in multiple columns. This example assumes that a ListBox control, named listBox1, has been added to a form.

[Visual Basic] 
Private Sub SetupMyMultiColumn()
   Dim x As Integer
   ' Add items to the ListBox.
   For x = 0 To 50
      ListBox1.Items.Add("Items " + x.ToString())
   Next x
   ' Display items in columns.
   ListBox1.MultiColumn = True
   ' Determine the width of the items in the list to get the best column width setting.
   Dim width As Integer = CInt(ListBox1.CreateGraphics().MeasureString(ListBox1.Items(ListBox1.Items.Count - 1).ToString(), _
      ListBox1.Font).Width)
   ' Set the column width based on the width of each item in the list.
   ListBox1.ColumnWidth = width
End Sub

[C#] 
private void SetupMyMultiColumn()
{
   // Add items to the ListBox.
   for (int x = 0; x < 50; x++)
   {
      listBox1.Items.Add("Items " + x.ToString());
   }
   // Display items in columns.
   listBox1.MultiColumn = true;
   // Determine the width of the items in the list to get the best column width setting.
   int width = (int) listBox1.CreateGraphics().MeasureString(listBox1.Items[listBox1.Items.Count -1].ToString(),
      listBox1.Font).Width;
   // Set the column width based on the width of each item in the list.
   listBox1.ColumnWidth = width;
}

[C++] 
private:
   void SetupMyMultiColumn()
   {
      // Add items to the ListBox.
      for (int x = 0; x < 50; x++)
      {
         listBox1->Items->Add(String::Format( S"Items {0}", __box(x)));
      }
      // Display items in columns.
      listBox1->MultiColumn = true;
      // Determine the width of the items in the list to get the best column width setting.
      int width = (int) listBox1->CreateGraphics()->
         MeasureString(
            listBox1->Items->Item[listBox1->Items->Count -1]->ToString(),
            listBox1->Font
         ).Width;
      // Set the column width based on the width of each item in the list.
      listBox1->ColumnWidth = width;
   }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

ListBox Class | ListBox Members | System.Windows.Forms Namespace | HorizontalScrollbar | ColumnWidth

Show:
© 2015 Microsoft