Freigeben über


ListBox.MultiColumn-Eigenschaft

Ruft einen Wert ab, der angibt, ob ListBox mehrere Spalten unterstützt, oder legt diesen fest.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

Syntax

'Declaration
Public Property MultiColumn As Boolean
'Usage
Dim instance As ListBox
Dim value As Boolean

value = instance.MultiColumn

instance.MultiColumn = value
public bool MultiColumn { get; set; }
public:
property bool MultiColumn {
    bool get ();
    void set (bool value);
}
/** @property */
public boolean get_MultiColumn ()

/** @property */
public void set_MultiColumn (boolean value)
public function get MultiColumn () : boolean

public function set MultiColumn (value : boolean)

Eigenschaftenwert

true, wenn die ListBox mehrere Spalten unterstützt; andernfalls false. Der Standardwert ist false.

Ausnahmen

Ausnahmetyp Bedingung

ArgumentException

Eine mehrspaltige ListBox darf keine Höhe mit variabler Größe aufweisen.

Hinweise

In einer mehrspaltigen ListBox werden Elemente auf so viele Spalten verteilt, wie zur Vermeidung vertikaler Bildläufe notwendig sind. Der Benutzer kann mithilfe der Tastatur zu Spalten navigieren, die derzeit nicht sichtbar sind. Legen Sie die HorizontalScrollbar-Eigenschaft auf true fest, um eine horizontale Bildlaufleiste anzeigen zu lassen, mit der Bildläufe zu Spalten durchgeführt werden können, die sich derzeit nicht im sichtbaren Bereich der ListBox befinden. Der Wert der ColumnWidth-Eigenschaft bestimmt die Breite der einzelnen Spalten.

Beispiel

Im folgenden Codebeispiel wird veranschaulicht, wie mit der ColumnWidth-Eigenschaft und der MultiColumn-Eigenschaft ein ListBox-Steuerelement erstellt wird, in dem Elemente in mehreren Spalten angezeigt werden. Für dieses Beispiel muss dem Formular das ListBox-Steuerelement listBox1 hinzugefügt werden.

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
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;
}
private:
   void SetupMyMultiColumn()
   {
      // Add items to the ListBox.
      for ( int x = 0; x < 50; x++ )
      {
         listBox1->Items->Add( String::Format( "Items {0}", x ) );

      }
      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;
   }
private void SetupMyMultiColumn()
{
    // Add items to the ListBox.
    for (int x = 0; x < 50; x++) {
        listBox1.get_Items().Add("Items " + System.Convert.ToString(x));
    }

    // Display items in columns.
    listBox1.set_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.
        get_Items().get_Item((listBox1.get_Items().get_Count() - 1)).
        ToString(), listBox1.get_Font()).get_Width());

    // Set the column width based on the width of each item in the list.
    listBox1.set_ColumnWidth(width);
} //SetupMyMultiColumn

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

ListBox-Klasse
ListBox-Member
System.Windows.Forms-Namespace
ListBox.HorizontalScrollbar-Eigenschaft
ListBox.ColumnWidth-Eigenschaft