[Solved] - DrawCell combine QueryCellStyle event question ?

Hi,
my datagrid has some columns, i used query_event to set cells forecolor with values "Yes" in green and "No" in red, also I have used Drawcell_event to number row_header
the problem I encountered was when selecting cells in the same row as in these 2 images:
first click:

second click:

looks like it lost backcolor! How do i avoid this?
Edit: I realize that the problem seems to occur when combining other select sets (extend or multi) to customize the selection
Thanks you!

4 Replies

VS Vijayarasan Sivanandham Syncfusion Team May 4, 2020 05:14 PM UTC

Hi Khanh Dang,

Thank you for contacting Syncfusion support.

Currently SfDataGrid does not contain a support for when maintain the TextColor when selection applied in datarow.
Your requirement can be achieved by override the OnRender method by using GridTextBoxCellRendererExt in SfDatGrid. Please refer the below code snippet,

 
this.sfDataGrid.CellRenderers.Remove("TextBox"); 
this.sfDataGrid.CellRenderers.Add("TextBox", new GridTextBoxCellRendererExt()); 
 
public class GridTextBoxCellRendererExt : GridTextBoxCellRenderer 
{ 
        protected override void OnRender(Graphics paint, Rectangle cellRect, string cellValue, CellStyleInfo style, DataColumnBase column, RowColumnIndex rowColumnIndex) 
        { 
            if (column.GridColumn.MappingName == "Country") 
            { 
                if (cellValue == "Yes") 
                    style.TextColor = Color.Green; 
                else if (cellValue == "No") 
                    style.TextColor = Color.Red; 
 
            } 
            base.OnRender(paint, cellRect, cellValue, style, column, rowColumnIndex); 
        } 
} 

UG Link:
https://help.syncfusion.com/windowsforms/datagrid/columntypes#customize-column-renderer

We hope this helps. Please let us know, if you require further assistance on this. 

Regards,
Vijayarasan S
 



TG The GridLock May 4, 2020 06:19 PM UTC

Hi Vijayarasan,
what I want to say is that the backcolor of the row is gone, I'll try your solution to fix the forecolor of the text.


TG The GridLock May 5, 2020 04:25 AM UTC

Hi Vijayarasan,
maybe because I have chosen Singledeselect as part while using keydown_event. I did not know how it works.


VS Vijayarasan Sivanandham Syncfusion Team May 5, 2020 11:08 AM UTC

Hi Khanh Dang,

We are glad to know that the reported issue has been resolved. Please get back to us if you have any other queries. As always, we will happy to assist you
😊

Regards,
Vijayarasan S



Loader.
Up arrow icon