Page 1 of 1
Dependent Scrolling List Field
Posted: Mon Apr 22, 2013 11:44 am
by kyoush
Hi there Livecoders,
I am trying to use two Scrolling List Field, where the content of the second depends on the selection in the first. e.g. if i select A in the first field, the second field shows 1,2,3 and if i select B in the first field, 4,5,6 are displayed as options in the second.
Is there a way to put the entire list of possibilities as contents of the second field and then selectively hide certain entries?
Or do i have to create a switch-case code fragment which erases and rewrites the contents of the second field?
Thanks for the help in advance.
Re: Dependent Scrolling List Field
Posted: Mon Apr 22, 2013 11:54 am
by snm
There are a lot of possibilities in LC. If it's my project I'll use arrays to keep data of field B "related" to data shown in field A and then display them in DataGrids or list fields.
Marek
Re: Dependent Scrolling List Field
Posted: Mon Apr 22, 2013 12:01 pm
by kyoush
Thanks for the tip Marek!
I'm a complete Newbie at LiveCode, but let me give that a try and check back if i run into hurdles.
Re: Dependent Scrolling List Field
Posted: Mon Apr 22, 2013 12:49 pm
by jmburnod
Hi kyoush,
As said Marek, you have many ways to do this
Using array is the best , but it is maybe less lisible than others
I did a little stack with your exemple
Let we know if you want others ways
Best regards
Jean-Marc
Re: Dependent Scrolling List Field
Posted: Mon Apr 22, 2013 5:18 pm
by snm
Clever done. I like it Jean-Marc.
So some little upgrade of defMylistInMU handler from me:
Code: Select all
-- Mouseup fld "MyListIn"
on defMylistInMU
put empty into fld MyListOut
put the short name of the target into tFld
put (the hilitedlines of fld tFld) into t
repeat for each item i in t
put item 1 of line i of fld tFld into tCat
put gMyArray[tCat] & cr after fld MyListOut
end repeat
delete last char of fld MyListOut
end defMylistInMU
Then if you set multipleHilite, nonContiguousHilite and toggleHilites properties of fld MyListIn, you can choose any quantity of "categories" and list all values of them.
Marek
Re: Dependent Scrolling List Field
Posted: Mon Apr 22, 2013 6:30 pm
by jmburnod
Hi Marek,
Yes. As expected, we are smarter together

Re: Dependent Scrolling List Field
Posted: Tue Apr 23, 2013 8:31 am
by kyoush
Thanks for the stack Jean-Marc. I might have fumbled a few things had i done that from scratch.
And thanks for the 'upgraded' handler Marek.
I don't have much use of the toggleHilites property in my use case, but multipleHilite and NonContiguousHilite could be useful.
I did some modifications of my own. What i wanted for the MyListOut field was not all the entries in a single line but in different lines so that i can select one of them. At first i replaced the last put command in defMylistInMU to replace the commas with cr before putting it in MyListOut.
But then realized it would be much more efficient to do this when creating the array itself, so ended up modifying debDoArray instead.
Code: Select all
-- Buiding array
on debDoArray
put fld "mylist" into t
put empty into tTheCat
repeat for each line tLine in t
put item 1 of tLine into tCat
put item 2 to -1 of tLine into tCont
replace "," with cr in tCont
put tCont into gMyArray[tCat]
put tCat & cr after tTheCat
end repeat
delete char -1 of tTheCat
put tTheCat into fld "MyListIn"
end debDoArray
I also replaced the
on mouseUp event handler with
on selectionChanged so that the MyListIn field can be controlled using the arrow keys.
I've attached the modified stack. Do let me know if you think there's a more efficient way of achieving this.
I also hope i've earned my keep to ask another question...
With the MyListIn field being controllable with arrow keys, it feels natural to use the Tab key to move to the next field, i.e. MyListOut. But upon doing so, using the arrow keys does not change the selection, even though the dotted box is visible which shows the focus has moved. Continuing to Tab takes the focus to Field and MyList which can be edited, but the two lists are not controllable. Any suggestions?
Re: Dependent Scrolling List Field
Posted: Thu Apr 25, 2013 1:40 am
by kyoush
A little digging around, and a little tinkering.. solution found! A little arrowKey handler in the card script:
Code: Select all
-- List navigation with arrow keys
on arrowKey pTheKey
if listBehavior of focusedObject is false then
pass arrowKey
exit arrowKey
end if
put the hilitedLine of focusedObject into tMyLine
if pTheKey is up then
put max(1,tMyLine-1) into tMyLine
else if pTheKey is down then
put min(number of lines of focusedObject,tMyLine+1) into tMyLine
else
pass arrowKey
end if
set the hilitedLine of focusedObject to tMyLine
end arrowKey
I must thank
Mark and his post in
another topic as i based the above off of his suggestion.
Updated stack attached.
@admins: if doable, could you change the topic title to prefix it with [Solved]. That should make it easier to spot.