We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Change color of grid cell text when model changes

I have overridden OnInitializeDisplayView in my GridCellTextViewRenderer-derived class to change text color depending on a boolean in my model.

        public override void OnUpdateDisplayValue(DataColumnBase dataColumn, SfLabel view)
        {
            base.OnInitializeDisplayView(dataColumn, view);
            if ((dataColumn.RowData as Player).InPlay == false)
            {
                view.TextColor = Color.FromRgba(50, 50, 50, 50);
            }
        }

and added it to the grid like this

            sfGrid.CellRenderers.Remove("TextView");
            sfGrid.CellRenderers.Add("TextView", new GridCellTextViewRendererExt());

This works find when the grid is first displayed, but if I change my underlying data model (in my case, after dragging a row to a new location) then my method above is not called, and the rows are drawn as default. How can I make this code called whenever the grid is drawn?

I've tried overriding OnUpdateDisplayValue

       public override void OnUpdateDisplayValue(DataColumnBase dataColumn, SfLabel view)
        {
            base.OnUpdateDisplayValue(dataColumn, view);
            if ((dataColumn.RowData as Player).InPlay == false)
            {
                view.TextColor = Color.FromRgba(50, 50, 50, 50);
            }
        }

but it is never called. Thanks.



1 Reply

AN Ashok N Syncfusion Team August 29, 2017 10:55 AM UTC

Hi Tino, 
 
Thanks for contacting Syncfusion support. 
 
You can achieve your requirement by overriding OnUpdateCellStyle method in custom GridCellTextViewRenderer class, please refer the below code example. Also we have prepared the sample based on your requirement and attached in the below location for your reference, please refer it . 
 
protected override void OnUpdateCellStyle(DataColumnBase dataColumn) 
{ 
    base.OnUpdateCellStyle(dataColumn); 
    // Enter Your code here   
} 
 
 
Regards, 
Ashok

Loader.
Live Chat Icon For mobile
Up arrow icon