Populating a specific index of a datagrid

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm

Populating a specific index of a datagrid

Post by quailcreek » Thu Jul 10, 2014 4:25 am

What I'm trying to do is search column "ID" in MyDataGrid for a match of the string in fld "ID"
When the strings match put a 1 at the index between the row that contains the string in fld "ID" and the column matching fld "Method"
What I have below works but it puts the "1" into the row 3 below the row where the string was found. In the if statement I have an answer theLineNo which validates the correct row number. So what am I doing wrong?

Tom
on mouseUp
put fld "Method" into theMethod
put fld "ID" into theID
put the dgNumberOfLines of grp "MyDataGrid" into theCount

repeat with theLineNo = 1 to theCount
put the dgDataOfLine[theLineNo] of grp "MyDataGrid" into theDataA
put theDataA["ID"] into foundID

if theID = foundID then
answer theLineNo
dispatch SetDataOfIndex to grp "MyDataGrid" with theLineNo,theMethod,"1"
end if
end repeat

send RefreshList to grp "MyDataGrid"
put the uSumOfColumn [theMethod] of group "MyDataGrid" into fld "Total"
end mouseUp
Tom
MacBook Pro OS Mojave 10.14

Klaus
Posts: 14211
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Populating a specific index of a datagrid

Post by Klaus » Thu Jul 10, 2014 10:28 am

Hi Tom,

BEWARE: INDEX <> LINE!

You need to stick to one of them TRHOUGHOUT :D
...
answer theLineNo
## dispatch SetDataOfIndex to grp "MyDataGrid" with theLineNo,theMethod,"1"
dispatch SetDataOfLine to grp "MyDataGrid" with theLineNo,theMethod,"1"
...
That should fix it.


Best

Klaus

quailcreek
Posts: 746
Joined: Sun Feb 04, 2007 11:01 pm

Re: Populating a specific index of a datagrid

Post by quailcreek » Thu Jul 10, 2014 4:44 pm

Thanks Klaus. Line instead of Index does make sense.

Tom
Tom
MacBook Pro OS Mojave 10.14

Post Reply