How Do I Use A Template In Multiple Data Grids?

If your application needs to use the same style of data grid in multiple places in your project then you can easily share the same row template between multiple data grids. This lesson will show you how.

Create First Data Grid

Create First Data Grid

The first step is to create your first data grid and customize the template (1). The data grid property that determines the Row Template that is used to draw the data grid is dgProps["row template"]. In the message box you can see that I queried this property in order to get a reference to the data grids row template (2).

Create Other Data Grids

Create Other Data Grids

Now you can add other data grids to your project. After adding the data grid you can set the dgProps["row template"] property to the long id of the first data grid's row template. Alternatively you could also do the following:

set the dgProps["row template"] of group "DataGrid 1" of stack "Untitled 1" to the dgProps["row template"] of group "DataGrid 1" of stack "my program"

Note: The Revolution IDE creates a card in the "Data Grid Template XXX" stack with a row template every time you drag a data grid on to a card. You may want to delete this card if you aren't going to be using the template.

The Result

The Result

Now both data grids will display data using the same template.


Barry G. Sumpter

Is there a way to copy the DataGrid and its template card to a new main stack?

Trevor DeVore

@Barry - you can copy a data grid to a new main stack just by selecting it, using Edit > Copy and pasting it. The new data grid will point to the original template, however, because the dgProps["row template"] property will still be the same.

If you want to point a data grid to point to a different template then just set the dgProps["row template"] of group "MyDataGrid" to the long id of a row template group. Setting this property is what you would do after copying your template card into a new main stack.

Add your comment

E-Mail me when someone replies to this comment