DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Checkedlistbox.CheckedItems Issue.

  1. #1
    Join Date
    Aug 2005

    Checkedlistbox.CheckedItems Issue.

    I am working with a checkedlistbox and I am having a small issue. Here is the code that I am using.

    Private Sub CListBox1_ItemCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles CListBox1.ItemCheck
    Dim itemchecked As Object

    For Each itemchecked In CListBox1.CheckedItems

    End Sub

    Now the problem that I am having is when I check an item in the listbox it is suppost to bring up a msgbox displaying each item that is checked, however; that isn't what happens. Instead I get a msgbox that displays all the times thats checked except for the one that I just checked.

    For example:
    I check Item#1 - Nothing happens
    Then I check Item #2 - Msgbox comes up with the name of Item#1 and then nothing else.
    Item# 3 - I get a msgbox for 1 & 2 but not 3 and so on.

    What am I doing wrong?

  2. #2
    Join Date
    Aug 2005
    I might also note that if I change:



    I get a msgbox displaying the number of items that is checked, however; it is also 1 short of what it should be.

  3. #3
    Join Date
    Aug 2005
    I think this event fires when you click on the item but before it is considered to be checked. This would allow some pre processing/validation before an item is selected.

  4. #4
    Join Date
    Nov 2003
    Portland, OR
    As noted in the documentation, the ItemCheck event "occurs when the checked state of an item changes." In other words, it's intended to provide information about the checked state of a single item, not the entire list.

    Try this:
    Private Sub CListBox1_ItemCheck(ByVal sender As Object, _ 
        ByVal e As System.Windows.Forms.ItemCheckEventArgs) _ 
        Handles CListBox1.ItemCheck
        ' Display msgbox for previous checked items
        For Each itemchecked As Object In CListBox1.CheckedItems
        ' If this event is fired because item was checked,
        If e.NewValue <> CheckState.Unchecked Then
            ' Display msgbox for newly-checked item
        End If
    End Sub
    Phil Weber

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

Similar Threads

  1. Deadlock issue in SQL Server
    By manumishra in forum Database
    Replies: 5
    Last Post: 06-09-2008, 04:28 PM
  2. Issue with VS.NET Find
    By Beginner in forum .NET
    Replies: 0
    Last Post: 01-27-2002, 06:35 PM
  3. Replies: 0
    Last Post: 09-19-2001, 06:48 AM
  4. bizzare issue w/ cells - not in UP sim
    By Michael in forum Mobile
    Replies: 1
    Last Post: 07-11-2001, 05:18 PM
  5. Application Server Newsletter Issue
    By John Lockwood in forum Web
    Replies: 1
    Last Post: 04-06-2000, 04:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center