Check boxes list.... item checked.
Check boxes list.... item checked.
Check boxes list.... item checked.
Check boxes list.... item checked.
Check boxes list.... item checked.
Check boxes list.... item checked. Check boxes list.... item checked. Check boxes list.... item checked. Check boxes list.... item checked. Check boxes list.... item checked. Check boxes list.... item checked. Check boxes list.... item checked. Check boxes list.... item checked.
Check boxes list.... item checked. Check boxes list.... item checked.
Check boxes list.... item checked.
Go Back  Xtreme Visual Basic Talk > > > Check boxes list.... item checked.


Reply
 
Thread Tools Display Modes
  #1  
Old 01-07-2011, 08:03 PM
WhatsMyUsername's Avatar
WhatsMyUsername WhatsMyUsername is offline
Regular
 
Join Date: Jan 2011
Location: Currently? Costa Rica
Posts: 52
Default Check boxes list.... item checked.


The check box list has an event called "ItemChecked" or something, which triggers when an item is about to change its checked status.

So, it is before the check occurs.

I couldn't find an event that occurs after the item has changed.. I want to execute some code only when an item is checked or unchecked.
Reply With Quote
  #2  
Old 01-07-2011, 11:47 PM
Frog's Avatar
Frog Frog is offline
Freshman
 
Join Date: Aug 2003
Location: Australia
Posts: 47
Default

Dim index As Integer
Private Sub CheckedListBox1_ItemCheck(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles CheckedListBox1.ItemCheck
index = CheckedListBox1.SelectedIndex
Label1.Text = index
End Sub

Private Sub CheckedListBox1_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles CheckedListBox1.MouseUp
If CheckedListBox1.GetItemCheckState(index) = CheckState.Checked Then
Label2.Text = index
Label3.Text = CheckedListBox1.SelectedItem.ToString
End If
End Sub

After clicking these, the mouse up event fires last. But to use mouse up you need index value

Last edited by Frog; 01-07-2011 at 11:48 PM. Reason: misspelling
Reply With Quote
  #3  
Old 01-08-2011, 08:16 AM
AtmaWeapon's Avatar
AtmaWeaponCheck boxes list.... item checked. AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

Frog, please use the [code] tags around sample code so your indentation is maintained.

Frog's technique will work, but with a little detective work you can do it all in the ItemCheck handler. As the documentation states, the event is raised before the state actually changes. This doesn't mean you can't tell if the item will be checked: if you know what it is now, and you know it's going to change, there's only one possible state it could be in. So if you receive the event when the item is unchecked, you know it is going to be checked. Even more convenient: the ItemCheckEventArgs.NewValue property tells you what the new value's going to be; I suppose I forgot there's a third state for checkboxes.
Code:
Private Sub CheckedListBox1_ItemCheck(ByVal sender As Object, ByVal e As ItemCheckEventArgs) Handles CheckedListBox1.ItemCheck
    Dim item As Object = CheckedListBox1.Items(e.Index)
    Dim newState As CheckState = e.NewValue

    Select Case newState
        Case CheckState.Checked
            ' The item will be checked
        Case CheckState.Indeterminate
            ' The item will be in the "Indeterminate" state; (it looks like this can't happen
            ' for the CheckedListBox.)
        Case CheckState.Unchecked
            ' The item will be unchecked
    End Select
End Sub
That's a good deal easier than trying to keep track of mouse state between several events, and avoids the pitfalls (you can easily create a scenario where the control never gets MouseUp.)
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #4  
Old 01-08-2011, 01:32 PM
Frog's Avatar
Frog Frog is offline
Freshman
 
Join Date: Aug 2003
Location: Australia
Posts: 47
Default

I also came up with this
Code:
    Private Sub CheckedListBox1_MouseUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles CheckedListBox1.MouseUp
        index = CheckedListBox1.SelectedIndex
        Label1.Text = index
        If CheckedListBox1.GetItemCheckState(index) = CheckState.Checked Then
            Label3.Text = ("Checked")
            Label2.Text = ("MouseUp")
        ElseIf CheckedListBox1.GetItemCheckState(index) = CheckState.Unchecked Then
            Label3.Text = ("Unchecked")
            Label2.Text = ("MouseUp")
        End If
    End Sub
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Check boxes list.... item checked.
Check boxes list.... item checked.
Check boxes list.... item checked. Check boxes list.... item checked.
Check boxes list.... item checked.
Check boxes list.... item checked.
Check boxes list.... item checked. Check boxes list.... item checked. Check boxes list.... item checked. Check boxes list.... item checked. Check boxes list.... item checked. Check boxes list.... item checked. Check boxes list.... item checked.
Check boxes list.... item checked.
Check boxes list.... item checked.
 
Check boxes list.... item checked.
Check boxes list.... item checked.
 
-->