CheckedListBox.ObjectCollection.Add 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
將一個項目加入 的項目列表中 CheckedListBox。
多載
| 名稱 | Description |
|---|---|
| Add(Object, Boolean) |
將一個項目加入 的項目列表中 CheckedListBox,指定要新增的物件以及是否被檢查。 |
| Add(Object, CheckState) |
將一個項目加入 的項目 CheckedListBox列表中,指定要新增的物件及初始檢查值。 |
Add(Object, Boolean)
將一個項目加入 的項目列表中 CheckedListBox,指定要新增的物件以及是否被檢查。
public:
int Add(System::Object ^ item, bool isChecked);
public int Add(object item, bool isChecked);
override this.Add : obj * bool -> int
Public Function Add (item As Object, isChecked As Boolean) As Integer
參數
- item
- Object
一個代表要加入收藏的物品的物件。
- isChecked
- Boolean
true檢查物品;否則,。 false
傳回
新加入項目的索引。
範例
以下程式碼範例示範如何初始化 CheckedListBox 控制項,方法是設定 CheckOnClick、 SelectionMode和 ThreeDCheckBoxes 屬性。 範例中將 輸入 控制 CheckedListBox 項,並將 設定 DisplayMember 為 Control.Name 該控制項的屬性。
要執行範例,將以下程式碼貼上一個包含 CheckedListBox CheckedListBox1 的表單,並從表單的建構子或Load方法呼叫該InitializeCheckListBox方法。
// 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 = gcnew CheckedListBox;
this->CheckedListBox1->Location = System::Drawing::Point( 40, 90 );
this->CheckedListBox1->CheckOnClick = true;
this->CheckedListBox1->Name = "CheckedListBox1";
this->CheckedListBox1->Size = System::Drawing::Size( 120, 94 );
this->CheckedListBox1->TabIndex = 1;
this->CheckedListBox1->SelectionMode = SelectionMode::One;
this->CheckedListBox1->ThreeDCheckBoxes = true;
System::Collections::IEnumerator^ myEnum = this->Controls->GetEnumerator();
while ( myEnum->MoveNext() )
{
Control^ aControl = safe_cast<Control^>(myEnum->Current);
this->CheckedListBox1->Items->Add( aControl, false );
}
this->CheckedListBox1->DisplayMember = "Name";
this->CheckedListBox1->Items->Add( CheckedListBox1 );
this->Controls->Add( this->CheckedListBox1 );
}
// 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);
}
' 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.
Friend WithEvents CheckedListBox1 As System.Windows.Forms.CheckedListBox
Private Sub InitializeCheckedListBox()
Me.CheckedListBox1 = New CheckedListBox
Me.CheckedListBox1.Location = New System.Drawing.Point(40, 90)
Me.CheckedListBox1.CheckOnClick = True
Me.CheckedListBox1.Name = "CheckedListBox1"
Me.CheckedListBox1.Size = New System.Drawing.Size(120, 94)
Me.CheckedListBox1.TabIndex = 1
Me.CheckedListBox1.SelectionMode = SelectionMode.One
Me.CheckedListBox1.ThreeDCheckBoxes = True
Dim aControl As Control
For Each aControl In Me.Controls
Me.CheckedListBox1.Items.Add(aControl, False)
Next
Me.CheckedListBox1.DisplayMember = "Name"
Me.CheckedListBox1.Items.Add(CheckedListBox1)
Me.Controls.Add(Me.CheckedListBox1)
End Sub
備註
此方法將項目加入清單。 對於清單,項目會被加入現有項目清單的末尾。 對於已排序的勾選清單框,項目會依照排序位置插入清單中。 當新物品的存放空間不足時,發生 A SystemException 事件。
適用於
Add(Object, CheckState)
將一個項目加入 的項目 CheckedListBox列表中,指定要新增的物件及初始檢查值。
public:
int Add(System::Object ^ item, System::Windows::Forms::CheckState check);
public int Add(object item, System.Windows.Forms.CheckState check);
override this.Add : obj * System.Windows.Forms.CheckState -> int
Public Function Add (item As Object, check As CheckState) As Integer
參數
- item
- Object
一個代表要加入收藏的物品的物件。
- check
- CheckState
項目中已檢查部分的首字母 CheckState 。
傳回
新加入項目的索引。
例外狀況
參數 check 並非有效 CheckState 值之一。
備註
此方法會將項目加入已勾選清單的方框。 對於未排序的勾選清單框,該項目會被加入現有項目清單的末尾。 對於已排序的勾選清單框,項目會依照排序位置插入清單中。 當新物品的存放空間不足時,發生 A SystemException 事件。