ListBox.MultiColumn 属性

定义

获取或设置一个值,该值指示 ListBox 是否支持多列。Gets or sets a value indicating whether the ListBox supports multiple columns.

public:
 property bool MultiColumn { bool get(); void set(bool value); };
public bool MultiColumn { get; set; }
member this.MultiColumn : bool with get, set
Public Property MultiColumn As Boolean

属性值

如果 ListBox 支持多个列,则为 true;否则为 falsetrue if the ListBox supports multiple columns; otherwise, false. 默认值为 falseThe default is false.

异常

多列 ListBox 的高度不能变化。A multicolumn ListBox cannot have a variable-sized height.

示例

下面的代码示例演示了一个简单的两列 ListBoxThe following code example demonstrates a simple two-column ListBox.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

public class Form1 : Form
{
    private ListBox listBox1;

    public Form1()
    {
        InitializeComponent();
    }
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Form1());
    }

    private void InitializeComponent()
    {
        this.listBox1 = new System.Windows.Forms.ListBox();
        this.SuspendLayout();
        // 
        // listBox1
        // 
        this.listBox1.FormattingEnabled = true;
        this.listBox1.HorizontalScrollbar = true;
        this.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"});
        this.listBox1.Location = new System.Drawing.Point(0, 0);
        this.listBox1.MultiColumn = true;
        this.listBox1.Name = "listBox1";
        this.listBox1.ScrollAlwaysVisible = true;
        this.listBox1.Size = new System.Drawing.Size(120, 95);
        this.listBox1.TabIndex = 0;
        this.listBox1.ColumnWidth = 85;
        // 
        // Form1
        // 
        this.ClientSize = new System.Drawing.Size(292, 273);
        this.Controls.Add(this.listBox1);
        this.Name = "Form1";
        this.ResumeLayout(false);

    }
}
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

注解

多列 ListBox 将项放入所需的列数,以使垂直滚动不必要。A multicolumn ListBox 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. HorizontalScrollbar 属性设置为 "true 以显示水平滚动条,该滚动条使用户能够滚动到当前未显示在 ListBox可见区域中的列。Set the HorizontalScrollbar property to true to display a horizontal scroll bar that enables the user to scroll to columns that are not currently shown in the visible region of the ListBox. ColumnWidth 属性的值确定每列的宽度。The value of the ColumnWidth property determines the width of each column.

适用于

另请参阅