5

I've got a program doing some processing of a CSV file and it's producing a DataTable as an output. I'm binding this to a DataGrid like so:

<DataGrid Name="GridTable" ItemsSource="{Binding OutputData}" />

Everything seems to work fine. The DataTable is produced, the DataGrid get's updated. But inexplicably the columns (type Double) don't seem to display their data. The first column (type int) works fine: DataGrid

When I double check the DataTable structure it's all there, and all the correct type. I'm getting no exceptions:

DataTable

The data binding clearly works as it's showing the columns and has the correct value in the first column.

Has anyone come across this before? Cheers

Joe
  • 6,773
  • 2
  • 47
  • 81

4 Answers4

1

Did you use

<DataGrid.Columns>
<DataGridTextColumn Header="" Binding="{Binding }"/>
</DataGrid.Columns> 

it should handle with doubles with no problem

Marcin
  • 427
  • 7
  • 21
1

It's caused by the way you name the columnname. Try to get rid of '/' in the columnname. I had experienced the same issue when I put the dots in the columnname.

B.S Lee
  • 23
  • 1
  • 6
0

Marcin's answer above led me to try binding columns individually, which led me here: programmatically add column & rows to WPF Datagrid

The solution was this:

            if (OutputData != null)
            {
                foreach (DataColumn col in OutputData.Columns)
                {
                    GridTable.Columns.Add(
                      new DataGridTextColumn
                      {
                          Header = col.ColumnName,
                          Binding = new Binding(string.Format("[{0}]", col.ColumnName))
                      });
                }

                GridTable.DataContext = OutputData;
            }
Community
  • 1
  • 1
Joe
  • 6,773
  • 2
  • 47
  • 81
0

i know that's been a long time, but if you are using db first integration, then nullable values are not showed in datagrid and also excel files. you can basically cast your nullable to int