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.ObjectCollection Count 專案的 。

此範例也會示範如何使用 SetItemCheckStateSetItemChecked 方法來設定專案的檢查狀態。 針對要檢查的每個其他專案, 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

備註

由 屬性從父控制項 CheckedListBox Items 存取集合。 若要建立要顯示在 控制項中的 CheckedListBox 物件集合,您可以使用 和 Remove 方法個別 Add 新增或移除專案。

建構函式

CheckedListBox.ObjectCollection(CheckedListBox)

初始化 CheckedListBox.ObjectCollection 類別的新執行個體。

屬性

Count

取得集合中的項目數目。

(繼承來源 ListBox.ObjectCollection)
IsReadOnly

取得值,表示集合是否為唯讀。

(繼承來源 ListBox.ObjectCollection)
Item[Int32]

取得或設定集合中位於指定索引處的項目。

(繼承來源 ListBox.ObjectCollection)

方法

Add(Object)

將項目加入至 ListBox 的項目清單。

(繼承來源 ListBox.ObjectCollection)
Add(Object, Boolean)

加入項目至 CheckedListBox 項目清單,指定所要加入的物件,不論它是否已選取。

Add(Object, CheckState)

加入項目至 CheckedListBox 項目清單,指定所要加入的物件和初始選取值。

AddRange(ListBox+ObjectCollection)

將現有 ListBox.ObjectCollection 的項目加入至 ListBox 中的項目清單中。

(繼承來源 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)

明確介面實作

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)

擴充方法

Cast<TResult>(IEnumerable)

IEnumerable 的項目轉換成指定的型別。

OfType<TResult>(IEnumerable)

根據指定的型別來篩選 IEnumerable 的項目。

AsParallel(IEnumerable)

啟用查詢的平行化作業。

AsQueryable(IEnumerable)

IEnumerable 轉換成 IQueryable

適用於