Sdílet prostřednictvím


CheckedListBox.SetItemCheckState(Int32, CheckState) Metoda

Definice

Nastaví stav kontroly položky v zadaném indexu.

public:
 void SetItemCheckState(int index, System::Windows::Forms::CheckState value);
public void SetItemCheckState(int index, System.Windows.Forms.CheckState value);
member this.SetItemCheckState : int * System.Windows.Forms.CheckState -> unit
Public Sub SetItemCheckState (index As Integer, value As CheckState)

Parametry

index
Int32

Index položky pro nastavení stavu.

value
CheckState

Jedna z CheckState hodnot.

Výjimky

Zadaná index hodnota je menší než nula.

nebo

Hodnota index je větší nebo rovna počtu položek v seznamu.

Není value to jedna z CheckState hodnot.

Příklady

Následující příklad vytvoří výčet položek v seznamu CheckedListBox a zkontroluje všechny ostatní položky v seznamu. Příklad ukazuje použití SetItemCheckState a SetItemChecked metody k nastavení stavu kontroly položky. Pro každou další položku, která má být kontrolována, SetItemCheckState je volána k nastavení CheckState na Indeterminate, zatímco SetItemChecked je volána u druhé položky nastavit stav zaškrtnutí na Checked.

Příklad také ukazuje použití Items vlastnosti získat CheckedListBox.ObjectCollection získat Count položky.

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

Poznámky

Metoda SetItemCheckState vyvolá ItemCheck událost.

Položky, jejichž CheckState je nastavena tak, aby Indeterminate se v zaškrtávacím políčku zobrazovaly se zaškrtnutím, ale je zobrazené šedě, které označuje nedeterminovaný stav zaškrtnuté položky.

Platí pro

Viz také