Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
| Search | Today's Posts | Mark Forums Read
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old December 20th, 2005, 02:11 PM
Authorized User
 
Join Date: Aug 2005
Location: , , .
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default Set Listbox Selected property

Hello,

I have a list box where I populate options, say
(1)
(2)
(3)
(4)

and I need to make vba select certain option (ie. say (2) and (4) dynamically)

I have a loop that determines which option should be selected, but I cant seem to use the listbox.Selected(item) property to select specific options with vba. (there is no error, it just doesnt select the options I need it to select) Any Ideas?



code:
Code:
For intCounter = 0 To listCounties.ListCount - 1

            If (Val(listCounties.ItemData(intCounter)) = Val(countiesRecordSet.Fields(0))) Then

                listCounties.Selected(intCounter) = True

          End If

        Next intCounter

Thanks

ÐaÐeVi£
__________________
ÐaÐeVi£
  #2 (permalink)  
Old December 21st, 2005, 11:47 AM
Authorized User
 
Join Date: Aug 2005
Location: , , .
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

anyone?

the loop works perfectly, its just the listCounties.Selected(intCounter) = True
part that doesnt do anything.


Thanks

ÐaÐeVi£
  #3 (permalink)  
Old December 21st, 2005, 01:50 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Alameda, ca, USA.
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

change the listbox property MultiSelect to 2 (extended)

Marco
  #4 (permalink)  
Old December 22nd, 2005, 11:24 AM
Authorized User
 
Join Date: Aug 2005
Location: , , .
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

the listbox is already on extended, but still doesnt work. I cant think of what could be wrong.


Thanks

ÐaÐeVi£
  #5 (permalink)  
Old December 22nd, 2005, 04:23 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Alameda, ca, USA.
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

put a break in the for loop, and check if the line that selects the list box item is really called (unless you already did it)

Marco
  #6 (permalink)  
Old December 23rd, 2005, 04:22 PM
Authorized User
 
Join Date: Aug 2005
Location: , , .
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, I tried that and it does get to the line, but it doesnt do anything when it gets there.



ÐaÐeVi£
  #7 (permalink)  
Old December 23rd, 2005, 06:40 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Alameda, ca, USA.
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

sorry, I do not any other ideas. The selected property works just fine with me

Marco
  #8 (permalink)  
Old October 4th, 2006, 04:04 PM
Registered User
 
Join Date: Oct 2006
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I had this problem and I realized that the list box was set to locked. No error, just nothing got selected. Setting locked property to no fixed this.


Similar Threads
Thread Thread Starter Forum Replies Last Post
ListBox not showing correct selected value Shokwave ASP.NET 2.0 Basics 4 June 4th, 2007 08:23 AM
Number of selected items in a listbox sarah lee ASP.NET 2.0 Basics 2 May 17th, 2007 12:20 PM
Get selected values from ListBox to DetailsView gerten ASP.NET 2.0 Professional 0 October 12th, 2006 01:21 PM
selected items in asp:ListBox jtyson Classic ASP Basics 2 July 2nd, 2004 12:01 AM
How to get selected Item from Listbox? Iceman571 ADO.NET 1 March 25th, 2004 06:33 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.