Qlik Community

QlikView App Development

Discussion Board for collaboration related to QlikView App Development.

Announcements
IMPORTANT: Upcoming LEF Database Maintenance, Oct. 3rd - SEE DETAILS
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Creator
Creator

Forcing selection in listbox according to item selection in other listbox with macro

Hi,

I would really appreciate some help with something im stuck with for a while now.

I came across this thread that has exactly what I want and implemented the macro into my model.

http://community.qlik.com/message/43182#43182  this is where you force a selection in a listbox.

I have two listboxes with codes in that are the same but form two different tables in my model. When you do a selection on one or more items in the one listbox it will cause the items with the same value in the other listbox to be selected. 

I have put in a messagebox in the macro to see if it picks up the selected value and it does – but for some reason it does not select the items in the other listbox.

Macro that I activate with a button as in sample app in link above

SUB GetSelectedValues

     SET fx = ActiveDocument.Fields("Code")              

     SET fy = ActiveDocument.Fields("TransCodeKey")

     SET fyV = fy.GetNoValues 

     FOR i = 0 TO fxV.Count -1                

           fyV.Add

           fyV(i).Text = fxV(i).Text

            msgbox(fyV(i).Text)

           fyV(i).IsNumeric = False

     NEXT

     fy.SelectValues fyV

    

END SUB

It works 100% in demo app but am I missing perhaps a setting somewhere in qlikview ? Can it be settings ? the 2 tables of mine are excatly the same - so it cant be that the values are not equal.

Thank you

Louw

screenshot.PNG

13 Replies
Highlighted
MVP & Luminary
MVP & Luminary

I'm guessing you are using V9? The double quote syntax -- which is only there only to handle the values with spaces -- doesn't seem to work in V9, but it does in V10. You can take out the " and it will work in V9, but only for values without spaces. There may be a form that works for V9, don't know off the top of my head.

-Rob

Highlighted
Not applicable

Yup - on 9. Now works. Thanks for the tip.

Stephen

Creator
Creator

Hi Rob,

I have implemented the action and it works 100% for my senario. In my case these two listboxes needs to have the same items filtered all the time. For instance my two listboxes contains products from two different tables - but products are the same. If i select one or more product in one listbox it will select the same product in other listbox.

But also now if i select a rep that is linked to the one product listbox - rep is linked to only certain products the same products will be selected in the other product listbox.

So what i did was just to implement your suggestion in the document event triggers(OnAnySelect) instead of the field event triggers because my listboxes must always have the same values filtered.

Thank so much for your help.

Regards

Louw

Highlighted
Not applicable

Hello, I implemented your script and it works great, but it doesn't work if I try to extend the selection to another listbox. I put your code on a field event trigger on select, then i tried to add a second trigger to control the selection of another field. The first trigger works the second doesn't. Am I doing something wrong? Is there a way to force selection on more than one listbox?

Thanks in advance.

Nicola