CheckedListBox.ObjectCollection 类

定义

表示 CheckedListBox 中项的集合。Represents the collection of items in a 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的项进行枚举, 并检查列表中的所有其他项。The following example enumerates the items in the CheckedListBox and checks every other item in the list. 该示例演示如何使用Items属性CheckedListBox.ObjectCollection获取以获取Count项的。The example demonstrates using the Items property to get the CheckedListBox.ObjectCollection to get the Count of items.

该示例还演示了如何SetItemCheckState使用SetItemChecked和方法来设置项的复选状态。The example also demonstrates using the SetItemCheckState and SetItemChecked methods to set the check state of an item. 对于要检查的每个其他SetItemCheckState项, 将调用以CheckState将设置为Indeterminate, 而SetItemChecked在另一项上调用以将选中状态设置为CheckedFor every other item that is to be checked, SetItemCheckState is called to set the CheckState to Indeterminate, while SetItemChecked is called on the other item to set the checked state to 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按属性访问集合。The collection is accessed from the parent control, CheckedListBox, by the Items property. 若要创建要在CheckedListBox控件中显示的对象的集合, 可以Add使用和Remove方法分别添加或移除项。To create a collection of objects to display in the CheckedListBox control, you can add or remove the items individually by using the Add and Remove methods.

构造函数

CheckedListBox.ObjectCollection(CheckedListBox)

初始化 CheckedListBox.ObjectCollection 类的新实例。Initializes a new instance of the CheckedListBox.ObjectCollection class.

属性

Count

获取集合中的项数。Gets the number of items in the collection.

(继承自 ListBox.ObjectCollection)
IsReadOnly

获取一个值,该值指示集合是否为只读。Gets a value indicating whether the collection is read-only.

(继承自 ListBox.ObjectCollection)
Item[Int32]

获取或设置集合中指定索引处的项。Gets or sets the item at the specified index within the collection.

(继承自 ListBox.ObjectCollection)

方法

Add(Object)

ListBox 的项列表添加项。Adds an item to the list of items for a ListBox.

(继承自 ListBox.ObjectCollection)
Add(Object, Boolean)

CheckedListBox 的项列表添加项,指定要添加的对象以及它是否选中。Adds an item to the list of items for a CheckedListBox, specifying the object to add and whether it is checked.

Add(Object, CheckState)

CheckedListBox 的项列表添加项,指定要添加的对象以及初始选中值。Adds an item to the list of items for a CheckedListBox, specifying the object to add and the initial checked value.

AddRange(ListBox+ObjectCollection)

将现有 ListBox.ObjectCollection 的项添加到 ListBox 中项的列表中。Adds the items of an existing ListBox.ObjectCollection to the list of items in a ListBox.

(继承自 ListBox.ObjectCollection)
AddRange(Object[])

ListBox 的项列表添加项的数组。Adds an array of items to the list of items for a ListBox.

(继承自 ListBox.ObjectCollection)
Clear()

从集合中移除所有项。Removes all items from the collection.

(继承自 ListBox.ObjectCollection)
Contains(Object)

确定指定的项是否位于集合内。Determines whether the specified item is located within the collection.

(继承自 ListBox.ObjectCollection)
CopyTo(Object[], Int32)

将整个集合复制到现有对象的数组中,从该数组内的指定位置开始复制。Copies the entire collection into an existing array of objects at a specified location within the array.

(继承自 ListBox.ObjectCollection)
Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetEnumerator()

返回一个枚举数,将使用该枚举数循环访问项集合。Returns an enumerator to use to iterate through the item collection.

(继承自 ListBox.ObjectCollection)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
IndexOf(Object)

返回指定的项在集合中的索引。Returns the index within the collection of the specified item.

(继承自 ListBox.ObjectCollection)
Insert(Int32, Object)

将一个项插入列表框中指定的索引处。Inserts an item into the list box at the specified index.

(继承自 ListBox.ObjectCollection)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
Remove(Object)

从集合中移除指定的对象。Removes the specified object from the collection.

(继承自 ListBox.ObjectCollection)
RemoveAt(Int32)

移除集合中指定索引处的项。Removes the item at the specified index within the collection.

(继承自 ListBox.ObjectCollection)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

显式界面实现

ICollection.CopyTo(Array, Int32)

从特定的数组索引开始,将集合的元素复制到数组中。Copies the elements of the collection to an array, starting at a particular array index.

(继承自 ListBox.ObjectCollection)
ICollection.IsSynchronized

有关此成员的说明,请参见 IsSynchronizedFor a description of this member, see IsSynchronized.

(继承自 ListBox.ObjectCollection)
ICollection.SyncRoot

有关此成员的说明,请参见 SyncRootFor a description of this member, see SyncRoot.

(继承自 ListBox.ObjectCollection)
IList.Add(Object)

将对象添加到 ListBox 类中。Adds an object to the ListBox class.

(继承自 ListBox.ObjectCollection)
IList.IsFixedSize

有关此成员的说明,请参见 IsFixedSizeFor a description of this member, see IsFixedSize.

(继承自 ListBox.ObjectCollection)

扩展方法

Cast<TResult>(IEnumerable)

IEnumerable 的元素强制转换为指定的类型。Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

根据指定类型筛选 IEnumerable 的元素。Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

启用查询的并行化。Enables parallelization of a query.

AsQueryable(IEnumerable)

IEnumerable 转换为 IQueryableConverts an IEnumerable to an IQueryable.

适用于