Ergodyne
Ergodyne

Reputation: 189

Binding an array of doubles to a datagrid

I'm trying to bind an array of doubles to a datagrid but the grid does not show the values of the double.

My grid looks like this:

<Grid>
  <DataGrid ItemsSource="{Binding}" AutoGenerateColumns="False" HorizontalAlignment="Stretch"
          Margin="5,5,5,5" Name="resultDataGrid1" VerticalAlignment="Stretch">
    <DataGrid.Columns>
      <DataGridTextColumn Header="Values" />
    </DataGrid.Columns>
  </DataGrid>
</Grid>

and in the code behind I have

private double[] _results = {0.012, 0.022};

...

resultDataGrid1.DataContext = _results;

The actual datagrid shows the number of rows (2) but the cells are all emtpy.

Upvotes: 0

Views: 2436

Answers (1)

svick
svick

Reputation: 244797

You have to tell the column what value to display. Since you want to display the whole value of the row, use:

<DataGridTextColumn Header="Values" Binding="{Binding}" />

Upvotes: 1

Related Questions