Dependent Scrolling List Field
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Dependent Scrolling List Field
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.
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.
...Livecode newbie, finding my way... 

Re: Dependent Scrolling List Field
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
Marek
Re: Dependent Scrolling List Field
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.
I'm a complete Newbie at LiveCode, but let me give that a try and check back if i run into hurdles.
...Livecode newbie, finding my way... 

Re: Dependent Scrolling List Field
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
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
- Attachments
-
- SimpleArray.livecode.zip
- (1.56 KiB) Downloaded 252 times
https://alternatic.ch
Re: Dependent Scrolling List Field
Clever done. I like it Jean-Marc.
So some little upgrade of defMylistInMU handler from me:
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
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
Marek
Re: Dependent Scrolling List Field
Hi Marek,
Yes. As expected, we are smarter together
Yes. As expected, we are smarter together

https://alternatic.ch
Re: Dependent Scrolling List Field
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.
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?

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'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?
- Attachments
-
- stArrayBasedDependentList_v2.zip
- A List dependent on another List example using Arrays
- (1.25 KiB) Downloaded 228 times
...Livecode newbie, finding my way... 

Re: Dependent Scrolling List Field
A little digging around, and a little tinkering.. solution found! A little arrowKey handler in the card script:
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.
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
Updated stack attached.
@admins: if doable, could you change the topic title to prefix it with [Solved]. That should make it easier to spot.
- Attachments
-
- stArrayBasedDependentList_v2.livecode.zip
- Dependent list field example, with arrow key list navigation
- (1.83 KiB) Downloaded 250 times
...Livecode newbie, finding my way... 
