6

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

4 Answers 4

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

Did you use

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

it should handle with doubles with no problem

Comments

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;
            }

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.