How can I change cell value after binding in SfDataGrid? (similar as DisplayText)

Dear, Sir or Madam,

I am developing Xamarin Android app with Syncfusion controls.

I got data from Ms-sql procedure then bound data in SfDataGrid. (Itemsource)

I would like to modify display text after binding. So I tried changing the value while QueryCellStyle.

But It didn't work becauese 'CellValue' is ready only.

How can I change display text? If no way, is there any other solution?

I attach the images what I am face a difficulty.

Database Data


What I want (developed by C#)



What I developed...



Best Regards,
Thanks.


5 Replies 1 reply marked as answer

PK Pradeep Kumar Balakrishnan Syncfusion Team February 16, 2021 01:44 PM UTC

Hi Sky, 
 
Thank you for contacting Syncfusion support. 
 
We have checked your requirement “How to change the display value without changing value in underlying collection and empty text should be displayed if the cell value is negative.” We cannot achieve this requirement directly in SfDataGrid. Currently, we are checking on the achieve your requirement, we will validate and update further detail on or before February 18, 2021. We appreciate your patience until then.  
 
Regards, 
Pradeep Kumar B 



SJ Sky Jang February 17, 2021 02:08 AM UTC

Hi Pradeep,

Thanks for your speedy reply.

I hope sfDataGrid supports changed display value during QueryCellStyle or after drawing the grid without modification of binding data .

Best Wishes,
Sky Jang


PK Pradeep Kumar Balakrishnan Syncfusion Team February 17, 2021 09:00 AM UTC

Hi Sky, 
 
Thank you for the update. 
 
We have prepared sample to achieve your requirement “How to modify display text of a particular cell without modifying underlying data in SfDataGrid”. Using DisplayBinding we have achieved your requirement. Refer to the following code snippet to achieve your requirement. 
 
Code Snippet: 
public class DisplayBindingConverter : IValueConverter 
{ 
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 
    { 
        if (value != null) 
        { 
            if (value.ToString() == "10001" || value.ToString() == "-1:0") 
            { 
                return null; 
            } 
            else 
            { 
                return value; 
            } 
        } 
                 
        return null; 
    } 
 
    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 
    { 
        return value; 
    } 
} 
 
 
 
If you are defining datagrid columns manually then use following code to define DisplayBinding. 
 
<sfgrid:SfDataGrid.Columns> 
                     
                    <sfgrid:GridTextColumn MappingName="OrderID" 
                                           DisplayBinding="{Binding OrderID, Converter={StaticResource displayBindingConverter}}"/> 
                     
                </sfgrid:SfDataGrid.Columns> 
 
 
 
 
If DataGrid columns are generated automatically then use DataGrid AutoGeneratingColumn event  
 
private void dataGrid_AutoGeneratingColumn(object sender, AutoGeneratingColumnEventArgs e) 
        { 
            e.Column.DisplayBinding = new Binding(e.Column.MappingName, converter: new DisplayBindingConverter()); 
        } 
 
 
 
We have also attached sample for your reference in the following link  
Sample   
 
 Kindly let us know if you need any further assistance on this.   
 
Regards, 
Pradeep Kumar B 


Marked as answer

SJ Sky Jang February 18, 2021 06:47 AM UTC

Hi Pradeep,

Thanks alot. It works well.

I appreciate your support.


Very truly yours,
Sky Jang.




PK Pradeep Kumar Balakrishnan Syncfusion Team February 18, 2021 07:19 AM UTC

Hi Sky, 
 
We are glad that the given solution meets your requirement. Please get in touch with us if you would require any further assistance in future. 
 
Regards, 
Pradeep Kumar B 


Loader.
Up arrow icon