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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Change Android SfDataGrid row colour programmatically in C#

Thread ID:

Created:

Updated:

Platform:

Replies:

149074 Nov 13,2019 03:33 PM UTC Nov 14,2019 07:24 PM UTC Xamarin.Android 1
loading
Tags: SfDataGrid
Ben
Asked On November 13, 2019 03:33 PM UTC

Hi,

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

Karthikraja Kalaimani [Syncfusion]
Replied On 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.Remove("TextView"); 
sfdataGrid.CellRenderers.Add("TextView", new CustomTextViewRenderer()); 
 
 
public class CustomTextViewRenderer : GridCellTextViewRenderer 
{ 
        public CustomTextViewRenderer() 
        { 
 
        } 
 
        protected override void OnRefreshDisplayValue(DataColumnBase dataColumn) 
        { 
            base.OnRefreshDisplayValue(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.

Regards,
 
Karthik Raja

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon