Tuesday, July 3, 2012

WPF DataGrid RowDetailsTemplate

WPF DataGrid provides a Row Details feature. Row details is simply a panel that shown for a selected row. Row Details may contain any thing you want to put there - label, textbox, button, picture...
WPF DataGrid RowDetailsTemplate example

In my example Row Details contains only two labels, let's take a look on MainWindow.xaml:
    <DataGrid ItemsSource="{Binding Employees}" AutoGenerateColumns="False">
                    <Label Content="Age: "/>
                    <Label Content="{Binding Age}"/>
            <DataGridTextColumn Header="Name" 
                                Binding="{Binding Name}"/>
            <DataGridTextColumn Header="Email" 
                                Binding="{Binding Email}"/>
            <DataGridTextColumn Header="Position" 
                                Binding="{Binding Position}"/>
Inside DataTemplate you can put anything you want, as you can see for this particular example I put two labels into DockPanel. Once user clicks on specific row Row Details will be shown automatically.
This is what we like in WPF - the flexibility it gives for a developer. Every control is a container - an infinite number of variation for creating GUI application.

Download the source code of this example (Visual Studio 2010).


  1. I've had good success putting another datagrid inside there, so you can drop down and display a whole set of related details easily - it gets a bit tricky with column headers, but for the right application, can work really well.

  2. how did you put another datagrid inside?

    1. Just put another DataGrid inside DataTemplate element.