This lesson will show you how to get data out of a data grid.
The Example Data Grid
Here is what the data grid looks like that I will be exporting data from.
The Handler For Populating Data Grid
command uiPopulatePeople
put "images/" into theImageFolder
put "Lucky" into theDataA[1]["FirstName"]
put "Day" into theDataA[1]["LastName"]
put "Three Amigo" into theDataA[1]["Title"]
put theImageFolder & "monkey.jpg" into theDataA[1]["Image URL"]
put "Dusty" into theDataA[2]["FirstName"]
put "Bottoms" into theDataA[2]["LastName"]
put "Three Amigo" into theDataA[2]["Title"]
put theImageFolder & "monkey.jpg" into theDataA[2]["Image URL"]
put "Ned" into theDataA[3]["FirstName"]
put "Nederlander" into theDataA[3]["LastName"]
put "Three Amigo" into theDataA[3]["Title"]
put theImageFolder & "monkey.jpg" into theDataA[3]["Image URL"]
put "Jane" into theDataA[4]["FirstName"]
put "Blue" into theDataA[4]["LastName"]
put "Secret Agent" into theDataA[4]["Title"]
put theImageFolder & "monkey.jpg" into theDataA[4]["Image URL"]
put "Jefferson" into theDataA[5]["FirstName"]
put "Blue" into theDataA[5]["LastName"]
put "Secret Agent" into theDataA[5]["Title"]
put theImageFolder & "monkey.jpg" into theDataA[5]["Image URL"]
lock screen
set the dgData of group "DataGrid 1" to theDataA
set the dgHilitedLines of group "DataGrid 1" to 1
unlock screen
end uiPopulatePeople
This is the code that was used to populate the data grid. This shows you the keys that each record has (FirstName, LastName, Title and Image URL).
Export Handler
command uiExportData
put the dgData of group "DataGrid 1" into theDataA
put the dgIndexes of group "DataGrid 1" into theIndexes
put "<people>" & cr into theXML
repeat for each item theIndex in theIndexes
put "<person>" & cr after theXML
put "<first_name>" & theDataA[theIndex]["FirstName"] & "</first_name>" & cr after theXML
put "<last_name>" & theDataA[theIndex]["LastName"] & "</last_name>" & cr after theXML
put "<title>" & theDataA[theIndex]["Title"] & "</title>" & cr after theXML
put "</person>" & cr after theXML
end repeat
put "</people>" after theXML
put theXML
end uiExportData
This is an example of how to get data out of a data grid. I begin by getting the dgData array and the dgIndexes. The indexes are a comma delimited list of the keys of the dgData in the proper order.
After you have the array and the ordered list of indexes you can loop through each record in the array. In this example I'm just wrapping the data in XML tags.
Example Output
This is what the output for my example looks like in the message box.
Comments (0)
Add your comment