0
votes

I would like to create datagrid that has nested columns (please look at attached image). Or if possible embed grid into cell. My objects have many different informations, and based on object type I would like to add additional info in my cell (nested Column in the image), that is divided by columns. Is it possible in silverlight ?

It would be perfect to just insert the whole new grid into cell, if possible.

TIA for any suggestions

Nested grid silverlight

2

2 Answers

0
votes

Sorry, I read "Grid" 8-)

For datagrid you'll be able to do it with datatemplates.

http://mscoder.wordpress.com/2010/09/11/nested-datagrid-using-silverlight-4-and-wcf/

0
votes

Leverage the LoadingRow event for your data grid to assign the appropriate datatemplate based on your datacontext.

Similar to my response to:

Enabling/Disabling row in a data grid

You do the following:

private void MyDataGrid_LoadingRow(object sender, DataGridRowEventArgs e)
{
    MyDataObjectClass dataContext = (e.Row.DataContext as MyDataObjectClass);

    foreach (DataGridColumn col in from cols in MyDataGrid.Columns orderby cols.DisplayIndex select cols)
    {
        FrameworkElement fe = col.GetCellContent(e.Row);

        DataGridCell result = fe.Parent as DataGridCell;

        // as an example, find a template column w/ a desired sort member path
        if (col is DataGridTemplateColumn && col.SortMemberPath == "x")
        {
            if (condition1)
            {
                result.ContentTemplate = (DataTemplate)Resources["NestedGridTemplate1"];
            }
            else 
            {
                result.ContentTemplate = (DataTemplate)Resources["NestedGridTemplate2"];
            }                   
        }
    }
}