SfDataGrid fails when bound to data table with column names containing special characters with autogenerate=true

Hi,

I am binding the SfDataGrid to a data table and have set AutoGenerateColumns = true.
One of the column name has a special character "\". This will cause bind errors and the value for this column will not be loaded in the grid.
A solution I came across with special characters was to wrap the mapping name value with [].
e.g if the column name was "Trade/Order", we set the MappingName="[Trade/Order]". 
This is fine when we are manually specifying columns. Is there a similar solution when autogeneratecolumns is set to true?

Thanks,
Som

5 Replies

GT Gnanasownthari Thirugnanam Syncfusion Team March 7, 2018 11:09 AM UTC

Hi Som, 

As you specified in your update, you can define the MappingName in AutoGenerating event if it is having special character while set the AutoGenerateColumns true like below code example. 

void AssociatedObject_AutoGeneratingColumn(object sender, AutoGeneratingColumnArgs e) 
{ 
    //Here you can define the MappingName if it is having special character 
    if (e.Column.MappingName == "Country/ShipCity") 
    { 
        e.Column.MappingName = "[Country/ShipCity]"; 
    } 
} 

We have prepared the sample based on your requirement, you can download it from below mentioned location. 

Sample location: 

Please refer the below UG link for more details. 

Please let us know if you need further assistance on this, we will happy to assist you. 

Regards, 
Gnanasownthari T. 



SC Somanna Chottekalapanda March 7, 2018 11:22 AM UTC

Hi Gnanasownthari,

Thanks for the reply. 

The issue with this solution is that the sort/filter/grouping on these columns will stop working. See below.
I had raised another query for this issue. https://www.syncfusion.com/forums/136268/sfdatagrid-bound-to-data-table-with-autogeneratecolumns-true-formatting-numeric-columns

    

Thanks,
Som


GT Gnanasownthari Thirugnanam Syncfusion Team March 8, 2018 12:45 PM UTC

Hi Som, 

Please ignore our previous update. 

You can display the value in Display and perform the Filtering/Sorting/Grouping operation if MappingName of column having special character by using Display and value binding like below code example. 

void AssociatedObject_AutoGeneratingColumn(object sender, AutoGeneratingColumnArgs e) 
{  
    //You can dispaly the value and perform the sorting filtering opertaion if MappingName having special character. 
    if (e.Column.MappingName == "Country/ShipCity") 
    {              
        e.Column.DisplayBinding = new Binding("[Country/ShipCity]"); 
        e.Column.ValueBinding = new Binding("[Country/ShipCity]"); 
    } 
} 

We have modified the sample based on your requirement, you can download it from below mentioned location. 


Regards, 
Gnanasownthari T. 

 



SC Somanna Chottekalapanda March 8, 2018 01:21 PM UTC

Thanks Gnanasownthari. The solution works for me.


GT Gnanasownthari Thirugnanam Syncfusion Team March 9, 2018 04:51 AM UTC

Hi Som, 

Thank you for your update, 

Please let us know if you need further assistance on this, we will happy to assist you. 

Regards, 
Gnanasownthari T. 



Loader.
Up arrow icon