-1

My wpf app xaml is simple, only a datagrid:

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

In code behind, UserCollection is a DataTable:

private DataTable userCollection;
public DataTable UserCollection
{
    get { return this.userCollection; }
    set
    {
        this.userCollection = value;
        NotifyPropertyChanged();
    }
}

In ViewModel.cs, code is simple, create 2 columns and add a row:

this.UserCollection = new DataTable();
UserCollection.Columns.Add("col1", typeof(int));
UserCollection.Columns.Add("co.l2", typeof(int));

var r=UserCollection.NewRow();
r["col1"] = 1;
r["co.l2"] = 2;
UserCollection.Rows.Add(r);

But the 2nd column which hearder contains a dot cannot display the value in UI, you can see the picture.

Why?

enter image description here

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Bob
  • 107
  • 6

1 Answers1

0

I have found the solution, replace dot char to another char by using :

StringNameWithDot.Replace(".", "\x2024");

Wpf datatable column header cannot contain ".","/","[]", here is another link:

What is it about DataTable Column Names with dots that makes them unsuitable for WPF's DataGrid control?

Bob
  • 107
  • 6