CheckedListBox.SetItemCheckState(Int32, CheckState) Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Définit l’état de vérification de l’élément à l’index spécifié.
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)
Paramètres
- index
- Int32
Index de l’élément pour lequel définir l’état.
- value
- CheckState
Une des CheckState valeurs.
Exceptions
La index valeur spécifiée est inférieure à zéro.
- ou -
La index valeur est supérieure ou égale au nombre d’éléments de la liste.
Ce value n’est pas l’une CheckState des valeurs.
Exemples
L’exemple suivant énumère les éléments dans la CheckedListBox liste et vérifie tous les autres éléments de la liste. L’exemple montre l’utilisation des méthodes et SetItemChecked des SetItemCheckState méthodes pour définir l’état de vérification d’un élément. Pour tous les autres éléments à vérifier, SetItemCheckState est appelé pour définir la IndeterminateCheckState valeur , tandis qu’il SetItemChecked est appelé sur l’autre élément pour définir l’état Checkedvérifié sur .
L’exemple montre également l’utilisation de la Items propriété pour obtenir CheckedListBox.ObjectCollection les Count éléments.
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
Remarques
La SetItemCheckState méthode déclenche l’événement ItemCheck .
Éléments dont CheckState la valeur est définie avec Indeterminate une coche dans la case à cocher, mais la case est grisée pour indiquer l’état indéterminé de l’élément coché.