CheckedListBox.SetItemCheckState(Int32, CheckState) Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Imposta lo stato di controllo dell'elemento in corrispondenza dell'indice specificato.
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)
Parametri
- index
- Int32
Indice dell'elemento per cui impostare lo stato.
- value
- CheckState
Uno dei CheckState valori.
Eccezioni
L'oggetto index specificato è minore di zero.
oppure
index è maggiore o uguale al numero di elementi nell'elenco.
Non value è uno dei CheckState valori .
Esempio
Nell'esempio seguente vengono enumerati gli elementi nell'oggetto CheckedListBox e vengono controllati tutti gli altri elementi dell'elenco. Nell'esempio viene illustrato l'utilizzo dei SetItemCheckState metodi e SetItemChecked per impostare lo stato di controllo di un elemento. Per ogni altro elemento da controllare, SetItemCheckState viene chiamato per impostare su CheckStateIndeterminate, mentre SetItemChecked viene chiamato sull'altro elemento per impostare lo stato selezionato su Checked.
Nell'esempio viene inoltre illustrato l'utilizzo della Items proprietà per ottenere l'oggetto CheckedListBox.ObjectCollection per ottenere l'oggetto Count degli elementi.
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
Commenti
Il SetItemCheckState metodo genera l'evento ItemCheck .
Elementi i cui CheckState elementi sono impostati per Indeterminate essere visualizzati con un segno di spunta nella casella di controllo, ma la casella è disattivata per indicare lo stato indeterminato dell'elemento selezionato.