How Do I Add A Row Of Data To An Existing Data Grid?
Sometimes you may want to add a row of data to a Data Grid without having to set the dgData or dgText property. You can add a single row of data by calling the AddData or AddLine commands of a Data Grid.
To use AddData you create an array containing the values for the new row. Here is an example of how to add a new row and have it appear as line 1 in a Data Grid. This example script resides outside of the Data Grid group script so AddData is not in the message path. This is why the dispatch command is used.
put "First Name" into theDataA["FirstName"] put "Last Name" into theDataA["LastName"] put "Title" into theDataA["Title"] put 1 into theLineNo dispatch "AddData" to group "DataGrid" with theDataA, theLineNo put the result into theNewIndex -- integer if successful, error string otherwise
To use AddLine you create a tab delimited string of text containing the values for the new row. You also need to tell the Data Grid the names of the columns that the data should map to. Here is an example of how to add a new row and have it appear as the last line in a Data Grid. This example script resides inside the Data Grid group script so AddLine is in the message path.
put "First Name" & tab & "Last Name" & tab & "Title" into theRowData put "FirstName" & cr & "LastName" & cr & "Title" into theDataColumns put the dgNumberOfLines of me + 1 into theLineNo AddLine theRowData, theDataColumns, theLineNo
Scrolling Data Into View And Getting The Data Control
After you add the data to the Data Grid you may want to scroll the new row into view. You can call ScrollIndexIntoView or ScrollLineIntoView to do this.