Search code examples
c#wpfxamldatagrid

Assign DataGridRow.Header Value from DataRow Nth column


I have a DataTable Dt as a ItemsSource for my DataGrid and I was wondering if there is any way to bind a cell value from Nth column to each DataGridRow.Header?

<DataGrid ItemsSource="{Binding Dt}">
    <DataGrid.RowStyle>
        <Style TargetType="DataGridRow" BasedOn="{StaticResource {x:Type DataGridRow}}">
            <!-- how to bind value from Dt Nth column?-->
            <Setter Property="Header" Value="{Binding} "/>
        </Style>
    </DataGrid.RowStyle>
</DataGrid>

Currently my output looks like this:

enter image description here


Solution

  • Try this where N = 1:

    <Style TargetType="DataGridRow" BasedOn="{StaticResource {x:Type DataGridRow}}">
        <Setter Property="Header" Value="{Binding [1]}"/>
    </Style>