Using ScrollLineIntoView and ScrollIndexIntoView

Last update: Saturday, 27 November, 2010

start conditionInitially, the Datagrid is populated with a list of song titles. The scrolling field containing the Datagrid is too small to show all of the titles.

first m pressedA script is used to recognize a keypress. ScrollLineIntoView is set to the number of the line corresponding to the first occurence of a title that starts with the corresponding letter (ScrollLineIntoView 235, for example).
This is what happens when the M-key is pressed. As you can see, scrolling occurs in such a way as to place the first title beginning with that letter at the bottom of the field.

s is pressedThe same sort of behaviour is observed when the S-key is then pressed: scrolling occurs in such a way as to place the first title beginning with that letter at the bottom of the field.

second m pressedHowever, pressing the M-key again provides a more correct result, with the first title beginning with that letter now appearing at the top of the scrolling field.

g pressedThis same correct behaviour is repeated when the letter "g" is pressed. It seems that, when scrolling towards the top of the list, the ScrollLineIntoView has a different effect to when moving to the bottom of the list! Just to prove it, let's press the M-key againÉ

m pressed againAnd indeed, scrolling down towards the bottom of the list (from the G titles to the M titles) results in the first M title being displayed as the last line of the DataGrid window.