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 Android SfDataGrid row colour programmatically in C#


I wish to change the row colour based on he data. This is in Xamarin Android, not Forms and is in c#. Data is stored in a DataTable and then used to fill the SfDataGrid

For example, I want all rows with the value "Y" in column 10 to be green.

How can this be done with the SfDataGrid?

Thank you

1 Reply

KK Karthikraja Kalaimani Syncfusion Team November 14, 2019 07:24 PM UTC

Hi Ben,

Thanks for Contacting Syncfusion support,

Your requirement can be achieved by overriding the GridCellTextViewRenderer class in SfDataGrid. We have prepared a sample for the same. In that sample, we have applied green for a particular row only if DataTable contains with Row value as “3” or “8”.

Please follow the below code example,

sfdataGrid.CellRenderers.Add("TextView", new CustomTextViewRenderer()); 
public class CustomTextViewRenderer : GridCellTextViewRenderer 
        public CustomTextViewRenderer() 
        protected override void OnRefreshDisplayValue(DataColumnBase dataColumn) 
        protected override void OnLayout(RowColumnIndex rowColumnIndex, View view, int left, int top, int right, int bottom) 
            var rowData = ((view as GridCell).DataColumn.RowData as DataRowView).Row.Table.Rows[rowColumnIndex.RowIndex - 1]; 
            base.OnLayout(rowColumnIndex, view, left, top, right, bottom); 
            var count = rowData.Table.Columns.Count; 
            for (int i = 0; i <= count - 1; i++) 
                if (rowData.ItemArray[i].ToString().Contains("3") || rowData.ItemArray[i].ToString().Contains("8") ) 
                    (view.Parent as View).SetBackgroundColor(Color.Green); 
We hope this helps, please let us know if need further assistance from us.

Karthik Raja

Live Chat Icon For mobile
Up arrow icon