<sigh> never mind. I just realized that if the datagrid gets re-sorted, there 
IS NO WAY to determine the next visible line in a datagrid. Kinda sucks. 

Bob S


> On Jul 31, 2024, at 11:01 AM, Bob Sneidar via use-livecode 
> <use-livecode@lists.runrev.com> wrote:
> 
> Hi all. 
> 
> Has anyone tried to determine the index of the next line of a datagrid? It’s 
> not as straightforward as you might think. When data is first loaded into a 
> datagrid, the dgIndexes are only going to be in numeric order if the sort 
> order of the datagrid is the same as the data you are loading. Otherwise, the 
> indexes will be all mixed up, but the dgLines of the datagrid will ALWAYS be 
> in the order of the visible rows. 
> 
> Sure you can just add one to the current dgHilitedLine, but what if you want 
> to know the index of the next line just before deleting the current one? You 
> cannot delete the line first because then the line numbers change, and there 
> won’t be another line hilited until your code sets it. 
> 
> And while there is a dgIndexOfLine property built in, there is no 
> dgLineOfIndex! Not only that, but there is a dgIndexes property, but there is 
> no dgLines property! How odd is that?? The goal is to determine the index of 
> the next visible line where the line numbers are no longer sequential. 
> 
> So I wrote some very simple virtual properties that ought to be a part of the 
> datagrid library. You can put these in the script of a datagrid itself, or if 
> you are brave enough to use the inline behaviors feature of datagrids as I 
> do, you can put them in your own datagrid custom library. But really they 
> belong in the built-in datagrid library itself. They are: 
> 
> getProp dgNextIndexOfLine [tLine]
>   put tLine +1 into tNewLine
> 
>   if tNewLine > the dgNumberOfLines of me then
>      put the dgIndexOfLine [tLine] of me into tIndex
>   else 
>      put the dgIndexOfLine [tNewLine] of me into tIndex
>   end if
> 
>   return tIndex
> end dgNextIndexOfLine
> 
> getProp dgPrevIndexOfLine [tLine]
>   put tLine -1 into tNewLine
> 
>   if tNewLine <1 then
>      put the dgIndexOfLine [tLine] of me into tIndex
>   else 
>      put the dgIndexOfLine [tNewLine] of me into tIndex
>   end if
> 
>   return tIndex
> end dgPrevIndexOfLine
> 
> You are welcome. :-)
> 
> Bob S
> 
> _______________________________________________
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your subscription 
> preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode

_______________________________________________
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode

Reply via email to