Page 1 of 1

selectionChanged for datagrids

Posted: Fri Aug 07, 2009 9:14 pm
by Paul D
I found an example stack that uses this method to populate the datagrid...

put revDatabaseColumnNames(sCursorID) into sRecordFields
put revNumberOfRecords(sCursorID) into sRecordCount
set the dgNumberOfRecords of group "datagrid 1" to sRecordCount

command GetDataForLine pLine, @pOutData
revMoveToRecord sCursorID, pLine - 1
put ConvertCurrentRowToArray() into pOutData
end GetDataForLine

function ConvertCurrentRowToArray
local theArray
repeat for each item theField in sRecordFields
put revDatabaseColumnNamed(sCursorID,theField) into theArray[theField]
end repeat
return theArray
end ConvertCurrentRowToArray


selectionChanged code...

on selectionChanged pHilitedIndex, pPrevHilitedIndex
put the dgDataOfIndex [ pHilitedIndex ] of me into theDataA
end selectionChanged


Result...
Image


If I use this method to populate the datagrid...

put revDatabaseColumnNames(sConnID, table) into theHeaders
put revDataFromQuery(,,sConnID,"SELECT * from table;") into theData
put 0 into x
repeat for each line dataLine in theData
add 1 to x
put 0 into y
repeat for each item headerTitle in theHeaders
add 1 to y
put item y of dataLine into arrayData[x][headerTitle]
end repeat
end repeat
set the dgData of group "datagrid 1" to arrayData



selectionChanged code...

on selectionChanged pHilitedIndex, pPrevHilitedIndex
put the dgDataOfIndex [ pHilitedIndex ] of me into theDataA
end selectionChanged


Result...
Image

Both ways of populating the datagrid show the correct data but why does selectionChanged work for one but not the other?

Posted: Sat Aug 08, 2009 2:31 am
by trevordevore
The first method uses a special feature of the data grid that is used for displaying really large amounts of data. Basically the data grid doesn't store any data internally but rather requests data (by calling GetDataForLine) for any data it needs to display. You can learn more about it here:

Displaying Large Amounts of Data

In the example you posted the data comes from a database. Rather than querying the data grid for data you would need to query the database. If you look at the sample stack associated with the above lesson the behavior for the data grid shows how you can store the database id in FillInData and then retrieving it in selectionChanged.

Posted: Mon Aug 10, 2009 1:03 pm
by Paul D
sounds good. thanks again.