Private Sub CheckedListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckedListBox1.SelectedIndexChanged Dim a As Integer = CheckedListBox1.CheckedItems.Count End Sub
Private Sub CheckedListBox1_ItemCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles CheckedListBox1.ItemCheck Dim lim As Integer lim = CheckedListBox1.CheckedItems.Count 'le check présent n'est pas encore comptabilisé avant la sortie de la sub (puisqu'on peut l'annuler) If e.CurrentValue = CheckState.Checked Then lim -= 1 Else lim += 1 Me.Text = lim.ToString End Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPublic Class Form1 Private WithEvents chkListBox As CheckedListBox Private lblCount As Label Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim chaine() As String = "elt1-elt2-elt3-elt4-elt5".Split("-") chkListBox = New CheckedListBox With chkListBox .Location = New Point(10, 10) .Size = New Size(300, 100) .Items.AddRange(chaine) End With lblCount = New Label With lblCount .Location = New Point(10, 150) .Text = chkListBox.CheckedItems.Count End With Me.Controls.Add(chkListBox) Me.Controls.Add(lblCount) End Sub Private Sub chkListBox_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles chkListBox.MouseUp lblCount.Text = chkListBox.CheckedItems.Count.ToString lblCount.Refresh() End Sub End Class