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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with linked listboxes

Status
Not open for further replies.

KDavie

Programmer
Feb 10, 2004
441
US
I have a form which contains 2 listboxes. List1 displays all the states. List2 is supposed to display all the counties for the selected state in list1. In the init event of the form I have this code:

lcStateName = ALLTRIM(thisform.list1.Value)
SELECT stateid
LOCATE FOR state = lcStateName
lnStateID = StateID
lcRowSource = 'SELECT county From countyids '
lcRowSource = lcRowSource + 'WHERE (stateID = lnStateID) INTO CURSOR crList'
WITH Thisform.list2
.RowSource = lcRowSource
.ListIndex = 1
ENDWITH


In the Valid event of list1 I have this code:

lcStateName = ALLTRIM(this.Value)
SELECT stateid
LOCATE FOR state = lcStateName
lnStateID = StateID
Thisform.list2.Requery()


The code almost works, except when the user clicks on a state in list1, list2 is populated with the correct counties then blinks and is populated by ALL counties in the table.


Any help would be appreciated.

-Kevin
 
Kevin,

At first glance, I'd say that this is because lnStateID is local to the Init and Valid events where it is referenced. The second listbox needs it be in scope the whole time. I suggest you make lnStateID a property of the form.

Mike


Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
Making stateID a property on the form doesn't work either. Here is exactly how I want it to work:

1. When the form opens list2 should display 'Select State'

2. Everytime the user selects a new state in list1, list2 should display the correct counties

Maybe I am going at it the wrong way all together, do you have any other suggestions?

Thanks for your help.

-Kevin
 
Nevermind, I got it to work. The stateID property was the key, I just forgot to update the code in one of the events. Thanks again for your help.

-Kevin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top