How to bind specific cell in datatgrid (WPF)?

I have 5 columns in my datagrid, and I need to just select a specific cell to bind my data. My datagrid row is fixed to 2 rows only.

1 answer

  • answered 2018-03-11 13:59 Fruchtzwerg

    Let's say there is a DataTable called Data in your view model bound to your ItemsSource of the DataGrid.

    <DataGrid ItemsSource="{Binding Data}"/>

    Binding a text block (or other controls) to the a specific index will work using the DataTable.DefaultView property and the index operators. Binding to the second row (index 1) and third row (index 2) will look like this:

    <TextBlock Text="{Binding Data.DefaultView[1][2]}"/>