CheckedListBox.SetItemChecked メソッドとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > CheckedListBox.SetItemChecked メソッドの意味・解説 

CheckedListBox.SetItemChecked メソッド

指定したインデックス位置にある項目の CheckState を Checked設定します

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

Public Sub SetItemChecked ( _
    index As Integer, _
    value As Boolean _
)
Dim instance As CheckedListBox
Dim index As Integer
Dim value As Boolean

instance.SetItemChecked(index, value)
public void SetItemChecked (
    int index,
    bool value
)
public:
void SetItemChecked (
    int index, 
    bool value
)
public void SetItemChecked (
    int index, 
    boolean value
)
public function SetItemChecked (
    index : int, 
    value : boolean
)

パラメータ

index

チェックの状態を設定する対象となる項目のインデックス

value

項目をチェックされている状態に設定する場合trueそれ以外場合false

例外例外
例外種類条件

ArgumentException

指定されインデックスが 0 未満です。

または

インデックスが、リスト内の項目数超える値です。

解説解説

true の値が渡されると、このメソッドによって CheckState の値が Checked設定されます。値が false のときは、CheckStateUnchecked設定されます。

使用例使用例

CheckedListBox 内の項目を列挙しリスト内の項目を 1 つおきにチェックする例を次に示します。この例では、SetItemCheckState メソッドおよび SetItemChecked メソッド使用して、項目のチェック状態を設定してます。チェックする項目は 1 つおきに、SetItemCheckState呼び出されCheckStateIndeterminate設定され残りの項目については SetItemChecked呼び出されチェック状態が Checked設定されます。

この例では、Items プロパティ使用して CheckedListBox.ObjectCollection を取得し次に Count取得する方法についても示します

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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照


このページでは「.NET Framework クラス ライブラリ リファレンス」からCheckedListBox.SetItemChecked メソッドを検索した結果を表示しています。
Weblioに収録されているすべての辞書からCheckedListBox.SetItemChecked メソッドを検索する場合は、下記のリンクをクリックしてください。
 全ての辞書からCheckedListBox.SetItemChecked メソッドを検索

英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

CheckedListBox.SetItemChecked メソッドのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



CheckedListBox.SetItemChecked メソッドのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS