CheckedListBox.SelectionMode 屬性

定義

取得或設定值以指定選取模式。

C#
public override System.Windows.Forms.SelectionMode SelectionMode { get; set; }

屬性值

SelectionModeOneNone 值。

例外狀況

嘗試指派不是 OneNone 值給 SelectionMode

嘗試指派 SelectionModeMultiExtended 值給控制項。

範例

下列程式碼範例示範如何設定 來初始化 CheckedListBox 控制項, SelectionMode 方法是將 設定為允許選取清單中的一個專案。

若要執行此範例,請將下列程式碼貼到包含 CheckedListBox 具名 CheckedListBox1 的表單中,並從表單的建構函式或 Load 方法呼叫 InitializeCheckListBox 方法。

C#
// This method initializes CheckedListBox1 with a list of all 
// the controls on the form. It sets the selection mode
// to single selection and allows selection with a single click.
// It adds itself to the list before adding itself to the form.

internal System.Windows.Forms.CheckedListBox CheckedListBox1;

private void InitializeCheckedListBox()
{
    this.CheckedListBox1 = new CheckedListBox();
    this.CheckedListBox1.Location = new System.Drawing.Point(40, 90);
    this.CheckedListBox1.CheckOnClick = true;
    this.CheckedListBox1.Name = "CheckedListBox1";
    this.CheckedListBox1.Size = new System.Drawing.Size(120, 94);
    this.CheckedListBox1.TabIndex = 1;
    this.CheckedListBox1.SelectionMode = SelectionMode.One;
    this.CheckedListBox1.ThreeDCheckBoxes = true;

    foreach ( Control aControl in this.Controls )
    {
        this.CheckedListBox1.Items.Add(aControl, false);
    }

    this.CheckedListBox1.DisplayMember = "Name";
    this.CheckedListBox1.Items.Add(CheckedListBox1);
    this.Controls.Add(this.CheckedListBox1);
}

備註

屬性 SelectionMode 會決定是否可以選取清單方塊中的一個專案,還是無法選取任何專案。 對於 CheckedListBox 物件,不支援多重選取。 您可以將模式設定為一個專案或沒有任何專案。

適用於

產品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

另請參閱