CheckedListBox.ObjectCollection 类
代表 CheckedListBox 中项的集合。
**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)
语法
声明
Public Class ObjectCollection
Inherits ObjectCollection
用法
Dim instance As ObjectCollection
public class ObjectCollection : ObjectCollection
public ref class ObjectCollection : public ObjectCollection
public class ObjectCollection extends ObjectCollection
public class ObjectCollection extends ObjectCollection
备注
可通过 Items 属性从父控件 CheckedListBox 访问该集合。若要创建要在 CheckedListBox 控件中显示的对象的集合,可以通过使用 Add 和 Remove 方法分别添加或移除这些项。
示例
下面的示例枚举 CheckedListBox 中的项并选中列表中的所有其他项。本示例演示了如何使用 Items 属性获取 CheckedListBox.ObjectCollection,从而获取项的 Count。
本示例还演示了如何使用 SetItemCheckState 和 SetItemChecked 方法设置项的复选状态。对于要选中的所有其他项,调用 SetItemCheckState 将 CheckState 设置为 Indeterminate,同时对另一项调用 SetItemChecked,将复选状态设置为 Checked。
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
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;
}
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.get_Items().get_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;
} //checkEveryOther_Click
继承层次结构
System.Object
System.Windows.Forms.ListBox.ObjectCollection
System.Windows.Forms.CheckedListBox.ObjectCollection
线程安全
此类型的任何公共静态(Visual Basic 中的 Shared)成员都是线程安全的,但不保证所有实例成员都是线程安全的。
平台
Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
请参见
参考
CheckedListBox.ObjectCollection 成员
System.Windows.Forms 命名空间