Articles in this section
Category / Section

How to display the column values when column name contains special characters?

1 min read

In the SfDataGrid, when special characters are used in the Column.MappingName for DataTable Collection, it results in binding error and the specific column value is not displayed in that column.

In the following code example, the column name contains special character, (“.”) fullstop. So, this column name is interrupted by binding path parser. The System.Windows.Data Error: 40 : BindingExpression path error: 'Na' property not found on 'object' ''DataRowView' (HashCode=9585198)'. BindingExpression:Path=Na.me; DataItem='DataRowView' (HashCode=9585198); target element is 'TextBlock' (Name=''); target property is 'Text' (type 'String')error is caused in the application since these special characters have meaning in binding path, including full stop (“.”), slash (“/”), and so on.

 

XAML

<Syncfusion:SfDataGrid x:Name="datagrid"  
                               AutoGenerateColumns="False"                             
                               AllowEditing="True"                                 
                               AllowDraggingColumns="True" 
                               AllowSorting="True"
                               ColumnSizer="Star"
                               NavigationMode="Cell"                             
                               ShowRowHeader="True"  >
<Syncfusion:SfDataGrid.Columns>
          <Syncfusion:GridTextColumn MappingName="Na.me" />
</Syncfusion:SfDataGrid.Columns>
</Syncfusion:SfDataGrid>     

 

C#

public MainWindow()
{
    InitializeComponent();
    this.datagrid.ItemsSource = InitializeDataTable();
}
private DataTable InitializeDataTable()
{
    DataTable table = new DataTable();
    System.Data.DataColumn dc2 = new System.Data.DataColumn("Na.me", typeof(string));
    table.Columns.Add(dc2);           
    return table;
}

 

You can overcome this issue by wrapping the binding path with square brackets in the Column.DisplayBinding. To display the value in edit mode, you need to do the same for the Column.ValueBinding.

XAML

<Syncfusion:SfDataGrid x:Name="datagrid"  
                               AutoGenerateColumns="False"                             
                               AllowEditing="True"                                 
                               AllowDraggingColumns="True" 
                               AllowSorting="True"
                               ColumnSizer="Star"
                               NavigationMode="Cell"                             
                               ShowRowHeader="True"  >
<Syncfusion:SfDataGrid.Columns>
          <Syncfusion:GridTextColumn MappingName="Na.me" 
                                  DisplayBinding="{Binding [Na.me]}" 
                                  ValueBinding="{Binding [Na.me]}"/>
</Syncfusion:SfDataGrid.Columns>
</Syncfusion:SfDataGrid>     

 

Sample Link:

WPF

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments
Please sign in to leave a comment
Access denied
Access denied