共用方式為


CheckedListBox.ObjectCollection 類別

定義

表示 中 的項目 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.ObjectCollection

範例

以下範例列舉了 中的 CheckedListBox 項目,並檢查列表中的其他項目。 範例展示了利用Items該財產來取得CheckedListBox.ObjectCollectionCount物品。

範例也示範使用 SetItemCheckStateSetItemChecked 方法來設定項目的檢查狀態。 對於其他要檢查的項目, 被 SetItemCheckState 呼叫來設定 CheckStateIndeterminate,而 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
Add(Object, Boolean)

將一個項目加入 的項目列表中 CheckedListBox,指定要新增的物件以及是否被檢查。

Add(Object, CheckState)

將一個項目加入 的項目 CheckedListBox列表中,指定要新增的物件及初始檢查值。

Add(Object)

將一個項目加入 的項目列表中 ListBox

(繼承來源 ListBox.ObjectCollection)
AddRange(ListBox+ObjectCollection)

將已存在ListBox.ObjectCollectionListBox的項目加入 。

(繼承來源 ListBox.ObjectCollection)
AddRange(Object[])

將一個項目陣列加入 ListBox

(繼承來源 ListBox.ObjectCollection)
Clear()

從集合中移除所有專案。

(繼承來源 ListBox.ObjectCollection)
Contains(Object)

判斷指定項目是否位於該收藏中。

(繼承來源 ListBox.ObjectCollection)
CopyTo(Object[], Int32)

將整個集合複製到陣列中指定位置的現有物件陣列中。

(繼承來源 ListBox.ObjectCollection)
Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetEnumerator()

回傳一個枚舉器,用來遍歷項目集合。

(繼承來源 ListBox.ObjectCollection)
GetHashCode()

做為預設哈希函式。

(繼承來源 Object)
GetType()

取得目前實例的 Type

(繼承來源 Object)
IndexOf(Object)

回傳指定項目集合內的索引。

(繼承來源 ListBox.ObjectCollection)
Insert(Int32, Object)

在指定的索引中插入一個項目。

(繼承來源 ListBox.ObjectCollection)
MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
Remove(Object)

會從集合移除指定的物件。

(繼承來源 ListBox.ObjectCollection)
RemoveAt(Int32)

移除集合中指定索引的項目。

(繼承來源 ListBox.ObjectCollection)
ToString()

傳回表示目前 物件的字串。

(繼承來源 Object)

明確介面實作

名稱 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 的專案。

適用於