Assign a different color to the CurrentItem

Hey,

We have a grid with a SelectionMode="Multiple". We need to display a different color to the CurrentItem from the other selected rows so the user can identify this row.

How can we achieve this task?

Thanks,
Mano



1 Reply

AN Ashok N Syncfusion Team June 12, 2018 11:14 AM UTC

Hi Mano, 
 
Thanks for contacting Syncfusion support. 
 
You can achieve your requirement by customizing GridCellTextViewRenderer. Please refer the below code example. 
 
public class GridCellTextViewRendererExt : GridCellTextViewRenderer 
{ 
    public GridCellTextViewRendererExt() 
    { 
 
    } 
 
    protected override void OnUpdateCellStyle(DataColumnBase dataColumn) 
    { 
        base.OnUpdateCellStyle(dataColumn); 
 
        if ((dataColumn as IElement).Element != null) 
        { 
            foreach (var item in this.DataGrid.SelectedItems) 
            { 
                var rowData = DataGrid.GetRowGenerator().Items.FirstOrDefault(x => x.RowData == item) as IRowElement; 
                if (rowData != null) 
                { 
                    rowData.Element.BackgroundColor = Color.Green; 
                } 
            } 
            var currentItem = DataGrid.GetRowGenerator().Items.FirstOrDefault(x => x.RowData == DataGrid.CurrentItem) as IRowElement; 
            if(currentItem != null) 
            { 
                currentItem.Element.BackgroundColor = Color.Red; 
            } 
        } 
    } 
} 
 
 
Regards, 
Ashok 


Loader.
Up arrow icon