Grid background colour.

8 posts, 0 answers
  1. Shaun
    Shaun avatar
    39 posts
    Member since:
    Sep 2012

    Posted 12 Dec 2012 Link to this post

    Hi,

    I must be missing something obvious but how do I set the background colour of a Gridview  control.
    I can set the background colour of a row or cell but I cannot see how to set the colour of "White space" in other words my grid takes up have the screen but it might only contain 2 rows, which I can colour, but the bank space is always white.

    Any ideas how I can change this??

    Cheers

    Shaun.

  2. Anton
    Admin
    Anton avatar
    167 posts

    Posted 14 Dec 2012 Link to this post

    Hello Shaun,

    Thank you for writing.

    You can change the background color of RadGridView through its table element. For example :
    this.radGridView1.TableElement.BackColor = Color.Red;

    Please note that by default cells and rows back colors are transparent, so if you change the color of table element, you should use RowFormatting (or change the design by a theme) event to set the row's desired color.

    I hope this helps.

    All the best,
    Anton
    the Telerik team
    Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
  3. Tony
    Tony avatar
    3 posts
    Member since:
    Jan 2013

    Posted 11 Feb 2013 Link to this post

    Hi,

    How would you format the 'nonclient' area of a subtable?

    I create my table in code, then create a subtable template and add the relationship.

    thanks
  4. Anton
    Admin
    Anton avatar
    167 posts

    Posted 13 Feb 2013 Link to this post

    Hi Tony,

    Thank you for writing.

    I am not sure what you mean with "'nonclient' area of a subtable", but I suppose that you want to change the color of the details view of hierarchical grid. If so, you can do this by subscribing to ViewCellFormatting event of the grid. For example:
    void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
    {
        if (e.CellElement is GridDetailViewCellElement)
        {
            e.CellElement.BackColor = Color.Red;
            e.CellElement.BackColor2 = Color.Red;
        }
    }

    If this is now what you are trying to achieve, please provide me with some screen shots where the desired area is marked, so I can provide you with adequate support.

    Let me know if you have additional questions.

    All the best,
    Anton
    the Telerik team
    Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
  5. Tony
    Tony avatar
    3 posts
    Member since:
    Jan 2013

    Posted 14 Feb 2013 Link to this post

    Hi, thanks for your reply

    The area I'm trying to shade is pointed to by the arrows in the attached image. The dark gray area of the main table shades perfectly with a

    m_Index.TableElement.BackColor = Color.FromArgb(64, 64, 64); but i can't seem to find anywhere to set the related subtable color the same.

    And your response has led me to a second question, for the gradient shaded cells i've had to use CustomizeFill = true on each GridViewCellInfo where I want a gradient shade. As whenever i do code similar to what you provided in ViewCellFormatting or in CellFormatting event it looks perfect until you move the mouse over the cell and it reverts to a flat shade. Is there much cost for having customised cell shading (I need some customised as they animate) so it seemed the sensible thing to do to make all of them shade using the same routines.

    Thanks in advanced

    tony
  6. Ivan Petrov
    Admin
    Ivan Petrov avatar
    718 posts

    Posted 19 Feb 2013 Link to this post

    Hello Tony,

    Thank you for writing back.

    The element the arrows point at is the table element of the grid details row cell. You can use the ViewCellFormatting event to change this color. Here is a code snippet which demonstrates how:
    private void radGridView1_ViewCellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e)
    {
        GridDetailViewCellElement cell = e.CellElement as GridDetailViewCellElement;
     
        if (cell != null)
        {
            cell.ChildTableElement.BackColor = Color.Gray;
        }
    }
    Again, as Anton mentioned in his first post, changing this color will change the colors of the rows/cells as they are transparent by default.

    I am not sure I fully understand your second question. The best way to customize cell elements is through the CellFormatting/ViewCellFormating events. There you have access to the actual element that will be painted and you can modify it. The formatting events are also fired for only the visible cells as they are the only elements created (thanks to the grid UI virtualization) so they are not slowing down the grid. If this does not answer your questions, I would kindly ask you to provide some more information on what you want to achieve.

    I hope this will be useful. Should you have further questions, do not hesitate to write back.

    Regards,
    Ivan Petrov
    the Telerik team
    Q3'12 SP1 of RadControls for WinForms is out now. See what's new.
  7. Tony
    Tony avatar
    3 posts
    Member since:
    Jan 2013

    Posted 21 Mar 2013 Link to this post

    That works a treat, thanks. Sorry it took so long to respond was off UI work for a bit.

    I'll try to think of a better way of explaining the other problem.

    Tony
  8. Ivan Petrov
    Admin
    Ivan Petrov avatar
    718 posts

    Posted 26 Mar 2013 Link to this post

    All right Tony I am glad that the first case is already resolved. In regards to the second one, I would need the code you are currently using, a screen shot of what is wrong in the formatting and screen shot of what you want to achieve and any steps needed to get in the unwanted state.

    I am looking forward to your reply when you have the time to prepare it.

    Greetings,
    Ivan Petrov
    the Telerik team
    WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
Back to Top