LiveCode LessonsData GridData Grid Tips & TricksGeneralHow Do I Scroll a Row To The Top of the Data Grid Form?

How Do I Scroll a Row To The Top of the Data Grid Form?

This lesson will show you how to scroll a particular row to the top of the Data Grid form using the dgRectOfIndex (or dgRectOfLine) property. This technique is useful when your rows are not a fixed height.

The Goal

The Goal

Here you can see that I have a selected row in a data grid (1). I want to scroll that row to the top of the data grid (2).

How To Do It

Here is the code that will scroll the selected line to the top of the data grid:

put the dgHilitedIndex of group "DataGrid" into theIndex
put the dgRectOfIndex [theIndex] of group "DataGrid" into theControlRect
put the rect of group "DataGrid" into theGridRect
put item 2 of theGridRect - item 2 of theControlRect into theOffset
set the dgVScroll of group "DataGrid" to the dgVScroll of group "DataGrid" - theOffset

The Result

The Result

After executing the code the row will be a moved to the top of the data grid.

4 Comments

Stam

I was interested in getting the rect of a row in a data grid and was relieved there was a dgRectOfIndex [rowIndex]... but using this does not return any data (just blank)? Doesn't seem to be in dictionary either... has this been depracated or am i missing something really basic?

Elanor Buchanan

Hi Stam

I just checked this in a simple Data Grid and it seems to work as expected. I created a simple DataGrid form with one field in the row template and set the dgData of the Data Grid.

I then executed

put the dgHilitedIndex of group "DataGrid" into tIndex
put the dgRectOfIndex[tIndex] of group "DataGrid"

and got back a rect.

Are you using a Data Grid form? This option is only available in forms, not tables.

If you could post your code here I would be happy to take a look at it.

Kind regards

Elanor

Klaus Major

And another term missing in the docs: dgRctOfIndex
This is neither in the dictionary nor in the "Data_Grid.pdf". :-/

Elanor Buchanan

Hi Klaus

I have reported a documentation bug for this.

https://quality.livecode.com/show_bug.cgi?id=22979

Kind regards

Elanor

Add your comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.