Results 1 to 4 of 4

CheckBox x ListBox - Loop Conflict

Threaded View

  1. #1
    Valued Forum Contributor Gatti's Avatar
    Join Date
    06-08-2015
    Location
    Brasil, São Paulo, Ribeirão Preto
    MS-Off Ver
    365
    Posts
    346

    CheckBox x ListBox - Loop Conflict

    Hello my friends... I got one issue with my Form's CheckBox and ListBox.

    When I click on the CheckBox, it unmarks/marks every item in ListBox...

    Works fine:

    Private Sub chb_MarkAll_Click()
        Dim iLoop   As Integer
    
        With frm_Files
            For iLoop = 0 To .lst_Files.ListCount - 1
                .lst_Files.Selected(iLoop) = .chb_MarkAll
            Next iLoop
        End With
    End Sub
    When I click on ListBox itens, if my click marks ALL itens, it marks the CheckBox

    Private Sub lst_Files_Change()    
        Dim iLoop   As Integer
        Dim booMark As Boolean
        
        booMark = True
        
        With frm_Files.lst_Files
            For iLoop = 0 To .ListCount - 1
                If Not .Selected(iLoop) Then
                    booMark = False
                    Exit For
                End If
            Next iLoop
        End With
        
        If booMark Then
            frm_Files.chb_MarkAll = True
        Else
            frm_Files.chb_MarkAll = False
        End If
    End Sub
    The problem is: When I try to put both codes together, they conflict

    What happens:
    * Cannot mark the Checkbox by clicking, because it activates the listbox event, and unmark the checkbox, because it runs the loop
    * When I mark by clicking all itens in listbox, checkbox gets marked, but when, after, I unmark one item, the checkbox gets unmarked, making the code of checkbox unmark ALL listbox itens

    Last edited by Gatti; 02-05-2016 at 05:03 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Loop find all matches of listbox items, display results in another listbox
    By banaanas in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-29-2015, 02:56 AM
  2. Listbox+checkbox = show info
    By mastaliyev in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-22-2014, 02:52 AM
  3. Updating a set of checkbox once a listbox changes
    By jsneak in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-20-2013, 07:03 PM
  4. Having problems populating a multicolumn listbox changing Listbox column with a loop.
    By Aristizabal95 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-11-2013, 12:41 PM
  5. Add or remove items with a checkbox into a listbox
    By Nuno Neves in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 12-30-2009, 01:19 PM
  6. Checkbox or listbox?
    By ahartman in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-07-2008, 12:10 PM
  7. VBA: Creating listbox similar to the one in Pivot table (Listbox+Checkbox)
    By modjoe23 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-18-2005, 09:35 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1