Page 1 of 2
Scrolling List loses selection when switching card
Posted: Sat Mar 24, 2018 9:47 am
by tluyben
When I put a List on Card 1 and selection of an item in that list + button click goes to Card 2, clicking back from Card 2 to Card 1 then shows the selected item on the List is now no longer selected. How can I make it hold selection when switching cards?
Re: Scrolling List loses selection when switching card
Posted: Sat Mar 24, 2018 11:21 am
by richmond62
The
listField contains this script:
on mouseUp
put the selectedLine of me into fld "SELECTION"
end mouseUp
The script to make sure the line is
reselected when you return to this card is in the
cardScript:
Code: Select all
on openCard
put fld "SELECTION" into XXX
select XXX
end openCard
Re: Scrolling List loses selection when switching card
Posted: Sat Mar 24, 2018 4:59 pm
by FourthWorld
Set the field's sharedText to true, place it in a group, set the group's sharedBehavior and backgroundBehavior to true.
Re: Scrolling List loses selection when switching card
Posted: Sat Mar 24, 2018 5:39 pm
by richmond62
Set the field's sharedText to true, place it in a group, set the group's sharedBehavior and backgroundBehavior to true.
While I am quite sure that is a far more elegant solution than my one,
could you possibly rephrase it in a somewhat less opaque fashion so
us "bottom feeders" could understand it.

Re: Scrolling List loses selection when switching card
Posted: Sat Mar 24, 2018 8:23 pm
by FourthWorld
These are properties available in the Inspector. Throughout LiveCode, as with many dev tools, objects have properties which govern common behavior. That set of property settings addresses the OP's need. For details on each they're described betterin the Dictionary than I could replicate here.
Re: Scrolling List loses selection when switching card
Posted: Sat Mar 24, 2018 8:44 pm
by jacque
FourthWorld wrote: ↑Sat Mar 24, 2018 4:59 pm
Set the field's sharedText to true, place it in a group, set the group's sharedBehavior and backgroundBehavior to true.
I did all that but it doesn't work here I'm afraid, though I have vague memories that it used to. I had to do this:
In field script:
Code: Select all
on mouseUp
set the cLine of me to the hilitedline of me
go next
end mouseUp
In group script:
Code: Select all
on preOpenControl
set the hilitedline of fld 1 of me to the cLine of fld 1
end preOpenControl
The preOpenControl handler will only work if the card you're coming from doesn't have that group placed.
Re: Scrolling List loses selection when switching card
Posted: Sat Mar 24, 2018 8:51 pm
by richmond62
Does this mean that hilitedLine is a synonym for selectedLine ?
Re: Scrolling List loses selection when switching card
Posted: Sat Mar 24, 2018 8:53 pm
by FourthWorld
jacque wrote: ↑Sat Mar 24, 2018 8:44 pm
FourthWorld wrote: ↑Sat Mar 24, 2018 4:59 pm
Set the field's sharedText to true, place it in a group, set the group's sharedBehavior and backgroundBehavior to true.
I did all that but it doesn't work here I'm afraid, though I have vague memories that it used to. I had to do this:
In field script:
Code: Select all
on mouseUp
set the cLine of me to the hilitedline of me
go next
end mouseUp
In group script:
Code: Select all
on preOpenControl
set the hilitedline of fld 1 of me to the cLine of fld 1
end preOpenControl
The preOpenControl handler will only work if the card you're coming from doesn't have that group placed.
I used to do that, and double-checked before posting to make sure a property-only approach would work. It does here in v9RC1, at least under Ubuntu 14.04. Just to make sure I just ran the recipe again - continues to work.
If the working behavior is limited to a single platform, that would seem a bug. And given how common this need is, it would seem a bug worth addressing.
Re: Scrolling List loses selection when switching card
Posted: Sat Mar 24, 2018 8:54 pm
by FourthWorld
richmond62 wrote: ↑Sat Mar 24, 2018 8:51 pm
Does this mean that
hilitedLine is a synonym for
selectedLine ?
No. They can sometimes be used in similar tasks, but return very different values. When in doubt the Dictionary contains useful details.
Re: Scrolling List loses selection when switching card
Posted: Sat Mar 24, 2018 11:15 pm
by jacque
Someone else should check the property method. I tested it as written and it didn't work in 9.rc1 on Mac. I may have missed something though.
Re: Scrolling List loses selection when switching card
Posted: Sat Mar 24, 2018 11:30 pm
by FourthWorld
I just tested on Mac and got the same good result. What are we doing differently? The complete steps I take are:
1. Create a new stack
2. Create a scrolling list field put
3. Use the Inspector to put some text in it.
4. In the Inspector, set the field's sharedText
5. Group it
6. In the Inspector, set the group's backgroundBehavior and the sharedBehavior
7. Choose browse tool
8. Click a line other than the first one to hilite it
9. Choose "Go Next" from the View menu
RESULT: the line I selected remains selected as I switch cards
Re: Scrolling List loses selection when switching card
Posted: Sat Mar 24, 2018 11:43 pm
by jacque
I turned off the group's sharedBehavior and it started working.
Odd, that.
Edit: I just noticed I'm in 8.1.9. I have several versions of LC running and got mixed up.
Re: Scrolling List loses selection when switching card
Posted: Sun Mar 25, 2018 12:53 am
by dunbarx
I have only just skimmed this thread, but isn't the easiest way to simply set a custom property of the list field to its hilitedLine , and on openCard, hilite that line?
Craig
Re: Scrolling List loses selection when switching card
Posted: Sun Mar 25, 2018 1:52 am
by FourthWorld
dunbarx wrote: ↑Sun Mar 25, 2018 12:53 am
I have only just skimmed this thread, but isn't the easiest way to simply set a custom property of the list field to its hilitedLine , and on openCard, hilite that line?
There are many ways to solve many things. We can write custom scripts to mirror most built-in property-driven behaviors if we want to. Personally, I prefer to let the engine do the work where I can, leaving script space free and open for things property settings can't do.
Re: Scrolling List loses selection when switching card
Posted: Sun Mar 25, 2018 1:29 pm
by richmond62
There are many ways to solve many things.
Indeed.
set the
script of the
listField to this:
Code: Select all
on mouseUp
set the LYNE of me to the selectedLine of me
end mouseUp
where
LYNE is a custom property of the
listField
then in the
cardScript:
Code: Select all
on openCard
put the LYNE of fld "myList" into LLINE
select LLINE
end openCard
I am sure someone a bit craftier than me can reduce the last script to something shorter.
