CheckedListBox.SetItemChecked(Int32, Boolean) 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 CheckState per l'elemento in corrispondenza dell'indice specificato su Checked.
public:
void SetItemChecked(int index, bool value);
public void SetItemChecked(int index, bool value);
member this.SetItemChecked : int * bool -> unit
Public Sub SetItemChecked (index As Integer, value As Boolean)
Parametri
- index
- Int32
Indice dell'elemento per cui impostare lo stato di controllo.
- value
- Boolean
true per impostare l'elemento come selezionato; in caso contrario, false.
Eccezioni
L'indice specificato è minore di zero.
oppure
L'indice è maggiore del numero di elementi nell'elenco.
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
Quando viene passato un valore di true , questo metodo imposta il CheckState valore su Checked. Valore di false imposta CheckState su Unchecked.