This is a migrated thread and some comments may be shown as answers.

How to change backcolor of cell in RadGridView?

1 Answer 1487 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Nickolay
Top achievements
Rank 1
Nickolay asked on 17 Jul 2017, 05:48 AM

My grid view has 2 handlers, that should handle cell and row formatting.

grid.RowFormatting += gridViewRaces_RowFormatting;

grid.CellFormatting += gridViewRaces_CellFormatting;

And this is their code:
private void gridViewRaces_RowFormatting(object sender, RowFormattingEventArgs e) {

      e.RowElement.DrawFill = true;

      e.RowElement.GradientStyle = GradientStyles.Solid;

      e.RowElement.RowInfo.Cells[2].Style.BackColor = Color.Blue;

}

 

private void gridViewRaces_CellFormatting(object sender, CellFormattingEventArgs e) {

      e.CellElement.DrawFill = true;

      e.CellElement.GradientStyle = GradientStyles.Solid;

      e.CellElement.BackColor = Color.Black;

}

}
But i've 2 problems:
1. Event CellFormatting doesn't fire on filling of Grid
2. RowFormatting is firing on filling of Grid, but color of cell doesn't change.
How to change cell color on GridView refresh/setting datasource?

1 Answer, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 17 Jul 2017, 10:07 AM
Hello Nickolay, 

Thank you for writing.  

Note that depending on the applied theme, the style may be specified either at the cell or at the row level. The RowFormatting and CellFormatting events are purposed to style the rows and cells respectively. It is not recommended to mix both events because you may not obtain the expected result. I would suggest you subscribe to the CellFormatting event at design time. Thus, you will be sure that the cells will be styled after populating with data. Additional information about formatting cells is available here: http://docs.telerik.com/devtools/winforms/gridview/cells/formatting-cells

If you are still experiencing any further difficulties, feel free to submit a support ticket providing a sample project demonstrating the problem. Thus, our support staff will gladly assist you.

I hope this information helps. Should you have further questions I would be glad to help.

Regards,
Dess
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
GridView
Asked by
Nickolay
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or