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 调用 以将 设置为 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

注解

通过 属性从父控件 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

适用于