CheckedListBox.ObjectCollection 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
表示 中 的項目 CheckedListBox集合。
public: ref class CheckedListBox::ObjectCollection : System::Windows::Forms::ListBox::ObjectCollection
public class CheckedListBox.ObjectCollection : System.Windows.Forms.ListBox.ObjectCollection
type CheckedListBox.ObjectCollection = class
inherit ListBox.ObjectCollection
Public Class CheckedListBox.ObjectCollection
Inherits ListBox.ObjectCollection
- 繼承
範例
以下範例列舉了 中的 CheckedListBox 項目,並檢查列表中的其他項目。 範例展示了利用Items該財產來取得CheckedListBox.ObjectCollectionCount物品。
範例也示範使用 SetItemCheckState 和 SetItemChecked 方法來設定項目的檢查狀態。 對於其他要檢查的項目, 被 SetItemCheckState 呼叫來設定 CheckState 到 Indeterminate,而 SetItemChecked 在另一個項目上 被呼叫將檢查狀態設為 Checked。
void CheckEveryOther_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
// Cycle through every item and check every other.
// Set flag to true to know when this code is being executed. Used in the ItemCheck
// event handler.
insideCheckEveryOther = true;
for ( int i = 0; i < checkedListBox1->Items->Count; i++ )
{
// For every other item in the list, set as checked.
if ( (i % 2) == 0 )
{
// But for each other item that is to be checked, set as being in an
// indeterminate checked state.
if ( (i % 4) == 0 )
checkedListBox1->SetItemCheckState( i, CheckState::Indeterminate );
else
checkedListBox1->SetItemChecked( i, true );
}
}
insideCheckEveryOther = false;
}
private void CheckEveryOther_Click(object sender, System.EventArgs e) {
// Cycle through every item and check every other.
// Set flag to true to know when this code is being executed. Used in the ItemCheck
// event handler.
insideCheckEveryOther = true;
for (int i = 0; i < checkedListBox1.Items.Count; i++) {
// For every other item in the list, set as checked.
if ((i % 2) == 0) {
// But for each other item that is to be checked, set as being in an
// indeterminate checked state.
if ((i % 4) == 0)
checkedListBox1.SetItemCheckState(i, CheckState.Indeterminate);
else
checkedListBox1.SetItemChecked(i, true);
}
}
insideCheckEveryOther = false;
}
Private Sub CheckEveryOther_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckEveryOther.Click
' Cycle through every item and check every other.
Dim i As Integer
' Set flag to true to know when this code is being executed. Used in the ItemCheck
' event handler.
insideCheckEveryOther = True
For i = 0 To CheckedListBox1.Items.Count - 1
' For every other item in the list, set as checked.
If ((i Mod 2) = 0) Then
' But for each other item that is to be checked, set as being in an
' indeterminate checked state.
If ((i Mod 4) = 0) Then
CheckedListBox1.SetItemCheckState(i, CheckState.Indeterminate)
Else
CheckedListBox1.SetItemChecked(i, True)
End If
End If
Next
insideCheckEveryOther = False
End Sub
備註
該集合由屬性從父控制CheckedListBoxItems項存取。 要建立一組物件在控制項中顯示 CheckedListBox ,你可以透過 Add and Remove 方法分別新增或移除這些項目。
建構函式
| 名稱 | Description |
|---|---|
| CheckedListBox.ObjectCollection(CheckedListBox) |
初始化 CheckedListBox.ObjectCollection 類別的新執行個體。 |
屬性
| 名稱 | Description |
|---|---|
| Count |
會取得收藏中的物品數量。 (繼承來源 ListBox.ObjectCollection) |
| IsReadOnly |
會獲得一個值,表示該集合是否為唯讀。 (繼承來源 ListBox.ObjectCollection) |
| Item[Int32] |
在集合中取得或設定該項目在指定的索引位置。 (繼承來源 ListBox.ObjectCollection) |
方法
明確介面實作
| 名稱 | Description |
|---|---|
| ICollection.CopyTo(Array, Int32) |
此 API 支援此產品基礎結構,但無法直接用於程式碼之中。 將集合的元素複製到陣列,從特定的陣列索引開始。 (繼承來源 ListBox.ObjectCollection) |
| ICollection.IsSynchronized |
關於此成員的描述,請參見 IsSynchronized。 (繼承來源 ListBox.ObjectCollection) |
| ICollection.SyncRoot |
關於此成員的描述,請參見 SyncRoot。 (繼承來源 ListBox.ObjectCollection) |
| IList.Add(Object) |
此 API 支援此產品基礎結構,但無法直接用於程式碼之中。 為類別新增一個物件 ListBox 。 (繼承來源 ListBox.ObjectCollection) |
| IList.Contains(Object) |
判斷是否 IList 包含特定值。 (繼承來源 ListBox.ObjectCollection) |
| IList.IndexOf(Object) |
決定特定項目的 IList索引。 (繼承來源 ListBox.ObjectCollection) |
| IList.Insert(Int32, Object) |
在指定的索引處插入一個項目 IList 。 (繼承來源 ListBox.ObjectCollection) |
| IList.IsFixedSize |
關於此成員的描述,請參見 IsFixedSize。 (繼承來源 ListBox.ObjectCollection) |
| IList.Item[Int32] |
取得或設定位於指定索引處的專案。 (繼承來源 ListBox.ObjectCollection) |
| IList.Remove(Object) |
移除特定物件 IList首次出現的 。 (繼承來源 ListBox.ObjectCollection) |
擴充方法
| 名稱 | Description |
|---|---|
| AsParallel(IEnumerable) |
啟用查詢的平行處理。 |
| AsQueryable(IEnumerable) |
將 IEnumerable 轉換成 IQueryable。 |
| Cast<TResult>(IEnumerable) |
將 IEnumerable 的項目轉換成指定的型別。 |
| OfType<TResult>(IEnumerable) |
根據指定的型別篩選 IEnumerable 的專案。 |