Updating datagrid but keep selected line

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
DavJans
Posts: 270
Joined: Thu Dec 12, 2013 4:21 pm
Location: Spokane, WA USA

Updating datagrid but keep selected line

Post by DavJans » Fri Jul 01, 2022 7:35 pm

I'm trying to keep the selected line after updating a datagrid.

Code: Select all

put the dgHilitedIndex of group "DataGridCutList" into cutlistLine
--Update datagrid
set the dgHilitedLines of group "DataGridCutList" to cutlistLine
This works great until I sort the datagrid. After sorting and selecting line 1 (visually) this happens

Code: Select all

put the dgHilitedIndex of group "DataGridCutList" into cutlistLine
answer cutlistLine  -- the answer is not 1 for this example lets say 2
--Update datagrid
set the dgHilitedLines of group "DataGridCutList" to cutlistLine
--It will hilite whatever line (visually) that the number is, in this case line 2 
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm" förutom här

Klaus
Posts: 13820
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Updating datagrid but keep selected line

Post by Klaus » Fri Jul 01, 2022 9:20 pm

Hi DavJans,

after sorting dgIndex <> dgLine, but dgIndex = dgIndex!
So I think just restoring the INDEX will solve this inconvenience:

Code: Select all

...
put the dgHilitedIndex of group "DataGridCutList" into cutlistLine
## answer cutlistLine  -- the answer is not 1 for this example lets say 2
## Update datagrid
## set the dgHilitedLines of group "DataGridCutList" to cutlistLine
set the dgHilitedIndex of group "DataGridCutList" to cutlistLine
...
Best

Klaus

DavJans
Posts: 270
Joined: Thu Dec 12, 2013 4:21 pm
Location: Spokane, WA USA

Re: Updating datagrid but keep selected line

Post by DavJans » Fri Jul 01, 2022 9:31 pm

OMG, what a stupid mistake, thank you
"Det bästa stället att hitta en hjälpande hand är i slutet av din egen arm" förutom här

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”