Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2013-12-27
7
2,015 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
This is about my first experience with programming Arduino.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

789 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