Silverlight Datagrid
This is my first blog on silverlight. Silver datagrid does not support hirarchical data directly. I had a task to create hirarchical datagrid in Silverlight. I have explored many options and during which I came to know about two good features. One is RowDetailsTemplate in Silverlight Datagrid and another is RowGrouping feature. This blog is about RowDetailsTemplate. Generally RowDetailsTemplate is used to display additional information of row. It has many advantages. First it does not affect dimension of rows and cells.Its visibility can be managed on row wise. To create RowDetailsTemplate for row in datagrid we have to set RowDetailsTemplate to as particulartemplate. It can hold any control. Following is an example of RowDetailsTemplate.
<data:datagrid name="datagrid1" row="0" column="0" rowdetailsvisibilitymode="Collapsed">
<data:datagrid.rowdetailstemplate>
<datatemplate>
<data:datagrid name="datagrid2" headersvisibility="None">
</data:datagrid>
</datatemplate>
</data:datagrid.rowdetailstemplate>
</data:datagrid>
As we can see from above code that we can put any control inside RowDetailsTemplate.
Here we have kept another grid inside RowDetailsTemplate.
Control insed row details share same datacontext as of datagrid so we can bound controls inside row details.
With RowDetailsVisibilityMode we can set visibility of row details it has three values.
1) Collpased: Row details are not visible.
2) Visible: Row details are visible.
3) VisibleWhenSelected:When row selected its row details will be visible.
Default value is VisibleWhenSelected. RowDetailsVisibilityChanged event is available when row details visibility changed. With RowDetailsVisibilityMode set to visible when selected, when row gets selectedRowDetailsVisibilityChanged event gets fired. This event also fires for the first row when another row is selected.
Also we can control details visibilty of individual row with DetailsVisibility property of Row.
In short RowDetailsTemplate is an powerful feature of silverlight datagrid. Developer can enhance interactivity and functionality of datagrid with this feature.
I have used this feature to create hirarchical datagrid. If you have any questions or comments plaese let me know.
-By Hiren Dave


