CheckedListBox.ObjectCollection クラス
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)


親コントロールである CheckedListBox で、Items プロパティを使用して、コレクションにアクセスします。CheckedListBox コントロールに表示するオブジェクトのコレクションを作成するには、Add メソッドおよび Remove メソッドを使用して、項目を個別に追加または削除します。

CheckedListBox 内の項目を列挙し、リスト内の項目を 1 つおきにチェックする例を次に示します。この例では、Items プロパティを使用して CheckedListBox.ObjectCollection を取得し、次に Count を取得する方法についても示します。
この例では、SetItemCheckState メソッドおよび SetItemChecked メソッドを使用して、項目のチェック状態を設定しています。チェックする項目は 1 つおきに、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.Windows.Forms.ListBox.ObjectCollection
System.Windows.Forms.CheckedListBox.ObjectCollection


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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からCheckedListBox.ObjectCollection クラスを検索する場合は、下記のリンクをクリックしてください。

- CheckedListBox.ObjectCollection クラスのページへのリンク