Page 1 of 1
[SOLVED] Getting the rect of a row in a data grid form?
Posted: Mon Nov 16, 2020 2:34 am
by stam
Hi all,
I have a group simulating a popover that I wish to appear on double-clicking a row in a data grid form.
The idea is to line up the middle of the popover group with the middle of the selected row like so:
I initially pleased to find the lesson
How Do I Scroll a Row To The Top of the Data Grid Form?, which suggests you can use
Code: Select all
the dgRectOfIndex [theIndex] of group "DataGrid"
but this
does not return any values and neither could i find reference to
dgRectOfIndex in the dictionary although may well have missed it.
Does this exist/is it deprecated or am missing something supremely obvious?
As an alternative i've come up with some highly suspicious math that doesn't fully work. It initially seemed to line up the popover perfectly, but when scrolling past 5 rows (so that the top visible row is row 5 or higher).the popover gets placed adjacent the next row down, so i'm clearly doing doing something wrong... :-/
Code: Select all
put the dgHilitedLines of group "data grid" into tRow
put item 1 of the dgVisibleLines of group "data grid" into tVisRows
put the dgProps["row height"] of group "data grid" into tRowHeight
put the top of group "data grid" into tTableTop
put (the height of group "popover")/2 into tOffset
put tTableTop + (tRow - tVisRows) * tRowHeight + tRowHeight/2 - tOffset into tTop
set the top of group "popover" to tTop
set the right of group "popover" to the left of group "data grid"
Grateful for any tips on this?
If
dgRectOfIndex does actually exist that would simplify the above to a couple of lines...
Re: getting the rect of a row in a data grid form?
Posted: Mon Nov 16, 2020 5:24 am
by dunbarx
Hi.
There is no "rect" property of a line in a DG as you wondered. There is no such property in the normal LC API. The kludge you made is just about what you need, though, but you need to change the last two lines to:
Code: Select all
set the top of fld "xx" to tTop + tRowheight
set the left of fld "xx" to the left of group "DataGrid 1"
Craig
Re: getting the rect of a row in a data grid form?
Posted: Mon Nov 16, 2020 7:43 am
by stam
Thanks Craig,
the
rect property i mentioned (dgRectOfIndex [theIndex]) was specifically and explicitly mentioned in the quoted, official,
liveCode lesson which is obviously wrong (sadly!). Just wanted to make sure i'm not missing something here, thank you for confirming.
Your solution won't fix the issue - my problem is:
- if i don't scroll the data grid down, the group is perfectly aligned.
- If i do scroll the data grid form down, then
after a certain point, the group starts appearing rows
below the intended one.
Adding the row height to the
top of the group for
all rows as suggested in your post will just make things worse....
Clearly the problem i'm having is estimating the cumulative height from top of the data grid
after scrolling past a certain point, but for now can't see the correct solution. Maybe will be more obvious when i'm more awake
I"ll try and make some time to created an isolated example with the relevant code...
Re: getting the rect of a row in a data grid form?
Posted: Mon Nov 16, 2020 3:00 pm
by dunbarx
I did not consider scrolling, only what you presented. And like you I did not see a "dgRectOfIndex" in the API.
But think about this another way. A dataGrid is simply (hah!) a collection of standard LC controls. Each "cell" in a dataGrid is in fact a field, and has a name. The first field, that is, the one in the upper left, is "field Col 1 0001". You can see how this works.
You can:
Code: Select all
answer the rect of fld "field 1 0001"
or whichever field you want. That gives you all the data you need to get the topLeft of any row. Scrolling does not matter, since the rect of a field in any particular hilited row is independent of the scroll value.
A semi-kludge.
Craig
Re: getting the rect of a row in a data grid form?
Posted: Mon Nov 16, 2020 3:05 pm
by stam
Thanks Craig,
I hadn’t considered that - very insightful.
That may well be the least kludgy way forward... will see the if I can use that - thank you!
Re: getting the rect of a row in a data grid form?
Posted: Mon Nov 16, 2020 3:09 pm
by dunbarx
Stam.
See my recent edit. Simpler, and actually all you need is the topLeft of a field living in the hilited row.
Craig
Re: getting the rect of a row in a data grid form?
Posted: Mon Nov 16, 2020 3:10 pm
by stam
Yep got that, thanks Craig. Should have really thought of it already but I guess I’m still thinking in terms of other more painful languages
Will have a go at it when I get home. Unfortunately day job first!
Thanks once again for the advice,
Stam
Re: getting the rect of a row in a data grid form?
Posted: Mon Nov 16, 2020 4:40 pm
by dunbarx
OK, let me know.
Should we make the "popover" track its line if you scroll the DG? Is that useful at all?
Craig
Re: getting the rect of a row in a data grid form?
Posted: Mon Nov 16, 2020 4:45 pm
by stam
Should be fairly simple to do, if this works.
The only unknown to me is if the rect of a field in a row is relative to the row or the stack.
If it’s the latter everything should be very straightforward...
Will test as soon as I get home and feed back!
Re: getting the rect of a row in a data grid form?
Posted: Mon Nov 16, 2020 4:56 pm
by dunbarx
The rect of any control is relative to the card window. This is a good thing. There are functions and properties such as the "screenMouseLoc" and the "screenLoc" that work in absolute coordinates.
Craig
Re: getting the rect of a row in a data grid form?
Posted: Tue Nov 17, 2020 1:31 am
by stam
referencing the rect of the field of the row certainly did it -- thanks again Craig
From your previous comment - scrolling the group with the listbox would be great, but can't find the handler that would detect the data grid scrolling - how would you do that?
-------------
EDIT: actually after quite a bit of searching i realised i could add a scrollbarDrag handler to the data grid - a wee bit jumpy but does the trick...
Re: [SOLVED] Getting the rect of a row in a data grid form?
Posted: Tue Nov 17, 2020 5:49 am
by dunbarx
Hi.
Check out the dgVScroll property.
Craig