Skip to content

DataTable Column Header containing "," symbol prevents cell rendering in WPF DataGrid #11163

@SreemonPremkumarM

Description

@SreemonPremkumarM

Description

When binding a System.Data.DataTable to a WPF DataGrid, if the DataColumn.ColumnName contains a "," (Comma), all subsequent cells in that column fail to display values.

In the output, it throws the binding error as ,

System.Windows.Data Error: 40 : BindingExpression path error: '[]' property not found on 'object' ''DataRowView' (HashCode=20668333)'. BindingExpression:Path=[a,b_0]; DataItem='DataRowView' (HashCode=20668333); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')

Datatable codes:

 DataTable dataTable = new DataTable();
 dataTable.Columns.Add("a,b", typeof(int));
 dataTable.Columns.Add("cb", typeof(string));
 dataTable.Columns.Add("Customer ID", typeof(string));
 dataTable.Columns.Add("Country", typeof(string));

 dataTable.Rows.Add(1001, "Maria Anders", "ALFKI", "Germany");
 dataTable.Rows.Add(1002, "Ana Trujilo", "ANATR", "Mexico");
 dataTable.Rows.Add(1003, "Antonio Moreno", "ENDGY", "Mexico");

Column Declaration:

 private void FradataGrid_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
 {
     e.Column = new DataGridTextColumn { Header = e.Column.Header, Binding = new Binding("[" + e.Column.Header + "]") };
 }

Sample Attached: DataGrid_WPF.zip

Reproduction Steps

  1. Run the attached sample.
  2. Observe the column "a,b0".
  3. Check the output for the binding error.

Expected behavior

The column "a,b0" display all values.

Actual behavior

Empty cells under the column "a,b0".

Regression?

No response

Known Workarounds

No response

Impact

No response

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions