Welcome! Log In Create A New Profile

Advanced

filling list based on another

Posted by Joel 
Joel
filling list based on another
March 03, 2009 04:38AM
I've been trying to create one list box based on a value in another and have had several problems.

First, I wanted to fill the second list when clicking on an item in the first. I couldn't figure out how to do it, there didn't seem to be a way in browser code. If someone has a way to do it, I'd love to see it.

Second, I finally opted for a button with code to fill the second list based on the first. The first list is filled by a embedded query. In the first list, I set a variable = to the value selected with this code in the "Whenever Modified" section:

i is int = ListSelect(Lst_Marketingcategories)
gpgsCampaignCategory = Lst_Marketingcategories

This didn't work, so I moved the code to a button under the "on Click" section. Then I tried to fill the second list box from code in the button like this:

//Clear Sub-Category List Box
ListDeleteAll(Lst_MarketingCategoryItems)

//Populate Sub-Category List Box
HReadSeekFirst(HFListItems,sListName,"CampaignType")
HReadSeekFirst(HFListItems,i1ActiveItem,True)
WHILE HFound()
HReadSeekFirst(HFListItems,sExtra,gpgsCampaignCategory)
If Hout() Then
Info("There are no Sub-categories for this Category")
Else
ListAdd(Lst_MarketingCategoryItems,HFListItems.sListItemCustom)
HReadNext()
END

END

This had inconsistent results, ultimately no working. Then I tried creating a query and basing the second list on that with a parameter which brings in the selected item from the first list. Haven't got this to work yet, but here's the code in the button I've got so far:

i is int = ListSelect(Lst_Marketingcategories)
gpgsCampaignCategory = Lst_Marketingcategories
Info(gpgsCampaignCategory)
HExecuteQuery(Qry_MarketingCampaignItems)
ListDisplay(Lst_MarketingCategoryItems)

ListDisplay by itself dosn't seem to refresh the list by itself, so I created a work around with a query and calling it before the ListDisplay command. While the help files say I can use the taReExecuteQuery parameter, it gives me an error when I try it.

I hope this makes sense to someone = as you can no doubt tell, I'm a newbie at this, but I thought I had it well enough to do this.

Any suggestions would be greatly appreciated.

Thanks!
Joel
Re: filling list based on another
March 03, 2009 04:50AM
OK, I got it working - I noticed I missed setting the param properly. I changed -

i is int = ListSelect(Lst_Marketingcategories)
gpgsCampaignCategory = Lst_Marketingcategories
Info(gpgsCampaignCategory)
HExecuteQuery(Qry_MarketingCampaignItems)
ListDisplay(Lst_MarketingCategoryItems)

to

i is int = ListSelect(Lst_Marketingcategories)
gpgsCampaignCategory = Lst_Marketingcategories
Info(gpgsCampaignCategory)
Qry_MarketingCampaignItems.ParamExtra = gpgsCampaignCategory
HExecuteQuery(Qry_MarketingCampaignItems)
ListDisplay(Lst_MarketingCategoryItems)

and it worked fine.

However, I would like to know if there is a way to do what I originally tried for, which was having the second list populated upon clicking an item in the first list. I also would like to be able to do this without the use of 'external queries' if possible.

thanks!
Joel
Re: filling list based on another
March 03, 2009 08:27PM
Well, I'm not sure exactly how, but I got this working just fine, double clicking on the first list and all... Sometimes I just don't know!
Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: