Using ScrollLineIntoView and ScrollIndexIntoView

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
exheusden
Posts: 170
Joined: Fri Oct 09, 2009 5:03 pm
Contact:

Using ScrollLineIntoView and ScrollIndexIntoView

Post by exheusden » Sat Nov 27, 2010 1:21 am

I have a problem with datagrids with the way that

scrollLineIntoView theLineNumber

works.

When a scroll towards the bottom of the grid is necessary, the line with line number theLineNumber is shown as the bottom line of the grid's field. However, when a scroll towards the top of the grid is needed, the line with line number theLineNumber is shown as the first line in the grid's field.

An example: I have a datagrid filled with some 500 song titles. Suppose it is in its initial state, with the titles beginning with the letter "A" showing in the grid's window and all other titles following these alphabetically. I know the line number of the first title of each letter of the alphabet and have a small script which recognizes a keypress and should position the titles accordingly by scrolling; if the letter "m" is typed, then the first title shown in the grid's field should be the first title starting with that letter, in other words. What happens is one of three things:

1. if no "m" titles are showing, but only titles with a letter earlier in the alphabet, then the grid scrolls so that the first "m" title is shown as the last line of the grid's field;
2. if at least one "m" title is showing, no scrolling at all takes place;
3. if no "m" titles are showing, but only titles with a letter later in the alphabet, then the grid scrolls so that the first "m" title is shown as the first line of the grid's field.

I want the third result to occur always (that the grid scrolls so that the first title beginning with the selected letter appears as the first line in the grid's field). Can this be achieved?


(The explanation above is confusing. I have therefore made a small page, containing visual examples of what happens. It can be found at http://davidneale.eu/livecode/scrolllineintoview.html)

Zryip TheSlug
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 163
Joined: Tue Jan 26, 2010 10:15 pm
Contact:

Re: Using ScrollLineIntoView and ScrollIndexIntoView

Post by Zryip TheSlug » Sat Nov 27, 2010 1:04 pm

exheusden wrote:I want the third result to occur always (that the grid scrolls so that the first title beginning with the selected letter appears as the first line in the grid's field). Can this be achieved?
Hi Exheusden,

Why not reset the scroll position before to go at the indexed position of the first letter?

command goToMyIndexedLine pTheIndex
dispatch "scrollLineIntoView" to grp "myDatagrid" with 1 -- reset the scroll at the top of the list
dispatch "scrollLineIntoView" to grp "myDatagrid" with pTheIndex
end goToMyIndexedLine

Note that with this way, scrolling at the top of the first letter of an index will only be possible if you have a sufficient amount of data at the end of the grid.

Example: you have a grid with 100 records and your grid manages 10 visibles rows. The user is already at the end of a list displaying:

91 x
92 y
93 y
94 y
95 y
96 y
97 z
98 z
99 z
100 z

For example, if the user search for the z lines, it will be not possible to have the first z line at the top of the visible lines because the user has reached the end of the list.


Regards,
TheSlug
http://www.aslugontheroad.com - Tutorials, demo stacks and plugins for LiveCode
Data Grid Helper - An intuitive interface for building LiveCode's Data Grids
Excel Library- Extends the LiveCode language for controlling MS Excel

exheusden
Posts: 170
Joined: Fri Oct 09, 2009 5:03 pm
Contact:

Re: Using ScrollLineIntoView and ScrollIndexIntoView

Post by exheusden » Sat Nov 27, 2010 2:51 pm

Thank you, Zryip TheSlug.

Your suggestion results in result 1. However, by setting the scroll initially to the last line and then going to the requested line, result 3 can be obtained.

Post Reply