Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listbox clearing issue

Status
Not open for further replies.

MichHart

Programmer
Dec 14, 2002
56
CA
Hi everyone and Happy New Year

I have a question about Listboxes. I have a Listbox set up with a checkbox so that the when the user selects an item from the list it will appear checked. My problem is when I clear it, all the items in the list disappear. I just want the checks to disappear, not the entire list.

Any suggestions

MichHart
 

"Unselect" the entry rather than clearing the listbox

List1.Selected(0) = False ' unselects the first item checkbox.


Mark
 
Try this

Private Sub MyListClear()
Dim i As Long
For i = 0 To List1.ListCount - 1
If List1.Selected(i) Then List1.Selected(i) = False
Next
End Sub If you choose to battle wits with the witless be prepared to lose.

[cheers]
 
Try using the .selected property. You will have to loop trough the items and set the .selected property for each item as below

Code:
Dim i As Integer
   For i = 0 To List1.ListCount - 1
      List1.Selected(i) = False
   Next i
Thanks and Good Luck!

zemp
 
Clear clears OUT the listbox (removes all nodes)

you need to do somthing like...


Code:
Dim node As Object
For Each node In ListBox.Nodes
  node.Checked = False
Next
Sometimes... the BASIC things in life are the best...
cheers.gif

or at least the most fun ;-)
-Josh Stribling
 
Well thanks everyone for all the suggestion. I will print this off and take a look at each one.

Regards,

Michelle
 
Cube, I don't wish to be rude, but could you at least read the questions rather than reading what you want in to them. A VB6 ListBox does not have a Nodes collection, although a TreeView[/b} does...
 
oops,
thanks strongm...
sorry MichHart...
I have a bad habbit of using TreeViews INSTEAD OF ListBoxes...
I usually Rename Them as lists...
Sorry for the confusion on my behalf...
And if I confused any one else...
Please Disregard my Above Coment Using Nodes...
And Use the method Zemp suggested...

Dim i As Integer
For i = 0 To List1.ListCount - 1
List1.Selected(i) = False
Next i

foada's method:

Private Sub MyListClear()
Dim i As Long
For i = 0 To List1.ListCount - 1
If List1.Selected(i) Then List1.Selected(i) = False
Next
End Sub

Also works... But the point is to CLEAR the check boxes...
So there is NO need to test to see if they are Checked...
Just Clear them all...

And... So My post won't be completely without worth... ;-)
if you ever use a TreeView... you can refer to my post to clear the checks ;-) Sometimes... the BASIC things in life are the best...
cheers.gif

or at least the most fun ;-)
-Josh Stribling
 
Thanks for all the suggestions and clarifications. Great site, great help!!


Dim i As Long
For i = 0 To lstList1.ListCount - 1
If lstList1.Selected(i) Then lstList1.Selected(i) = False
Next


MichHart " Never regret yesterday because it cannot be changed;
Instead make sure today does not become a regret of tomorrow."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top