Many ways to do what you want. Here is one simple.
-put the content of the 2 datagrids in 2 variables
put the dgText of group "master grid" into tMaster
put the dgText of group "reference grid" into tReference
-Now, you can, as you say, pick up the first row, and second column for instance
set itemdelimiter to tab
put item 2 of line 1 of tMaster into tChunk
-Now, you can look for tChunk in tReference. Again many ways to do this. Here is one method.
replace cr with tab in tReference
set the wholeMatches to true
put itemOffset(tChunk,tReference) into tResult
if tResult <>0 then
put item (tResult +1) of tReference into tFinish
answer tFinish
end if
This method has flaws. You could use arrays. You could even use SQLlite
Arrays are very powerfull.
If you put the content of reference in array It would make :
put "COOKIE" into reference[1]
put "CAKE" into reference[2]
put "PIE" into reference[3]
Then, it's very easy to pick up a cell by its number
put reference[tChunk] into tResult
Anyway. Here is a small stack with both methods.