CheckedListBox.SetItemCheckState(Int32, CheckState) Metoda
Definicja
Ważny
Niektóre informacje dotyczą produktów przedpremierowych, które mogą zostać znacznie zmodyfikowane przed premierą. Microsoft nie udziela żadnych gwarancji, ani wyraźnych, ani domniemanych, dotyczących informacji podanych tutaj.
Ustawia stan sprawdzania elementu w określonym indeksie.
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
Indeks elementu, dla który ma zostać ustawiony stan.
- value
- CheckState
Jedna z CheckState wartości.
Wyjątki
Określona index wartość jest mniejsza niż zero.
-lub-
Wartość index jest większa lub równa liczbie elementów na liście.
Wartość value nie jest jedną z CheckState wartości.
Przykłady
Poniższy przykład wylicza elementy na liście CheckedListBox i sprawdza każdy inny element na liście. W przykładzie pokazano użycie SetItemCheckState metod i SetItemChecked w celu ustawienia stanu sprawdzania elementu. Dla każdego innego elementu, który ma być sprawdzany, jest wywoływany, SetItemCheckState aby ustawić IndeterminateCheckState wartość , podczas gdy SetItemChecked jest wywoływany w innym elemencie, aby ustawić stan zaznaczone na Checked.
W przykładzie pokazano również użycie Items właściwości w celu pobrania CheckedListBox.ObjectCollectionCount elementów.
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
Uwagi
Metoda SetItemCheckState zgłasza ItemCheck zdarzenie.
Elementy, których CheckState ustawienie ma być Indeterminate wyświetlane z znacznikiem wyboru w polu wyboru, ale pole jest szare, aby wskazać nieokreślony stan zaznaczonego elementu.