Solved

VB6 - Uncheck/clear the listbox (with the style = checkbox)

Posted on 2013-12-27
7
1,953 Views
Last Modified: 2013-12-27
Hello,

How does one go about programmatically uncheck the list box's checkbox selections in vb6?
0
Comment
Question by:Jammerules
  • 4
  • 3
7 Comments
 
LVL 46

Expert Comment

by:Martin Liss
ID: 39743042
List1.Selected(0) = False

Where 0 is the ListIndex.
0
 

Author Comment

by:Jammerules
ID: 39743043
   
For x = 0 To lstFileList.ListCount - 1
      If lstFileList.Selected(x) = True Then
         lstFileList.Selected(x) = False
      End If
   Next

Open in new window


I have that code in place. But the problem is I also have another piece of code that triggers off upon ItemCheck event
Private Sub lstFileList_ItemCheck(Item As Integer)
    Dim i, j As Integer
    For i = 0 To lstFileList.ListCount - 1
        If lstFileList.Selected(i) = True Then
            ReDim Preserve arrSourceFilesToBExported(j)
            arrSourceFilesToBExported(j) = lstFileList.List(i)
            j = j + 1
        End If
    Next
End Sub

Open in new window

0
 
LVL 46

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 39743047
Create a form-level or global boolean variable. Something like

Public gbIgnore As Boolean

and then

gbIgnore = True
For x = 0 To lstFileList.ListCount - 1
      If lstFileList.Selected(x) = True Then
         lstFileList.Selected(x) = False
      End If
   Next
gbIgnore = False

Open in new window

and
Private Sub lstFileList_ItemCheck(Item As Integer)
    Dim i, j As Integer

    If gbIgnore Then Exit Sub

    For i = 0 To lstFileList.ListCount - 1
        If lstFileList.Selected(i) = True Then
            ReDim Preserve arrSourceFilesToBExported(j)
            arrSourceFilesToBExported(j) = lstFileList.List(i)
            j = j + 1
        End If
    Next
End Sub

Open in new window

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Closing Comment

by:Jammerules
ID: 39743049
Haha! I was just about doing what you said and I got your response! Thanks :)
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 39743050
And this code

gbIgnore = True
For x = 0 To lstFileList.ListCount - 1
      If lstFileList.Selected(x) = True Then
         lstFileList.Selected(x) = False
      End If
   Next
gbIgnore = False

Open in new window


could simply be

gbIgnore = True
For x = 0 To lstFileList.ListCount - 1
         lstFileList.Selected(x) = False
   Next
gbIgnore = False

Open in new window

0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 39743052
You're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2013
0
 

Author Comment

by:Jammerules
ID: 39743055
Yup... I glanced through your profile after your first response. I will definitely look into it time permitting! Thanks again for all the invaluable help from peeps like you on this forum.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This is about my first experience with programming Arduino.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now