Grid View

3 posts, 0 answers
  1. balasubramanyam
    balasubramanyam avatar
    5 posts
    Member since:
    Jan 2011

    Posted 20 Nov 2012 Link to this post

    How to change Style.BackColor property for particular Cell?
  2. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 20 Nov 2012 Link to this post


    Just handle the CellFormatting event, check for the column and the specific cell and set the backcolor, like so:
    void grid_CellFormatting(object sender, CellFormattingEventArgs e)
        if (e.Column.Name == "SomeColumn")
            var dataBoundObject = e.CellElement.RowInfo.DataBoundItem;
            // check if this matches your case
            e.CellElement.BackColor = Color.Red;
            e.CellElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);

    You have to keep in mind that because the grid reuses cell (just the displayed cells are created and drawn), you will have to reset the custom properties you set on the cell.

    Best Regards,
    Emanuel Varga
    WinForms MVP
  3. Plamen
    Plamen avatar
    132 posts

    Posted 22 Nov 2012 Link to this post

    Hi guys,

    Cells and rows can be styled by changing the data cells back color:
    e.CellElement.BackColor = Color.Red;
    e.CellElement.BackColor = Color.Green;
    e.CellElement.BackColor = Color.Blue;

    event is used to add formatting to grid data cells including the new row cells.
    While CellFormatting event is fired only for data cells, ViewCellFormatting is fired for all RadGridView cells. So if you want to format the grouping row or the header cells, you should use the ViewCellFormatting event.

    More information about the formatting abilities of the cells can be found in these documentation article:

    I hope this helps. Should you have any other questions, I will be glad to assist you.

    the Telerik team
    Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
Back to Top