By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,153 Members | 2,581 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,153 IT Pros & Developers. It's quick & easy.

List Box - select all

100+
P: 553
Hi

how to select all values in the ListBox on a button click ?

thanks
Qi
Aug 15 '07 #1
Share this Question
Share on Google+
5 Replies


P: 47
Expand|Select|Wrap|Line Numbers
  1. Cmd_Select_All_click
  2. For i = 0 To lstNames.ListCount - 1
  3.     lstNames.Selected(i) = True
  4. Next
  5. End Sub
There are probably more elegant soutions but this works fine for me. You can also write a Deselect All routine by subsitituting FALSE for TRUE.

Hope this helps
Aug 15 '07 #2

100+
P: 553
Hi

This method starts selecting all items until it reaches the last one.
When you reach the end of loop, only the last one is selected - not All.

Is that right, this is what i am getting!


Expand|Select|Wrap|Line Numbers
  1. Cmd_Select_All_click
  2. For i = 0 To lstNames.ListCount - 1
  3.     lstNames.Selected(i) = True
  4. Next
  5. End Sub
There are probably more elegant soutions but this works fine for me. You can also write a Deselect All routine by subsitituting FALSE for TRUE.

Hope this helps
Aug 15 '07 #3

ADezii
Expert 5K+
P: 8,669
Hi

This method starts selecting all items until it reaches the last one.
When you reach the end of loop, only the last one is selected - not All.

Is that right, this is what i am getting!
Mr. Barry07 left out 1 minor detail. The code will select ALL items in a List Box as long as the Multi Select Property is set to either Simple or Extended, but NOT None.
Aug 15 '07 #4

100+
P: 553
Thanks ADzii
......
Mr. Barry07 left out 1 minor detail. The code will select ALL items in a List Box as long as the Multi Select Property is set to either Simple or Extended, but NOT None.
Aug 15 '07 #5

ADezii
Expert 5K+
P: 8,669
Thanks ADzii
......
You are quite welcome, questionit.
Aug 15 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.