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

Grid background colour.

7 Answers 706 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Shaun
Top achievements
Rank 1
Shaun asked on 12 Dec 2012, 10:53 PM

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.

7 Answers, 1 is accepted

Sort by
0
Anton
Telerik team
answered on 14 Dec 2012, 09:59 AM
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.
0
Tony
Top achievements
Rank 1
answered on 11 Feb 2013, 09:08 AM
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
0
Anton
Telerik team
answered on 13 Feb 2013, 05:40 PM
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.
0
Tony
Top achievements
Rank 1
answered on 14 Feb 2013, 07:06 AM
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
0
Ivan Petrov
Telerik team
answered on 19 Feb 2013, 04:09 PM
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.
0
Tony
Top achievements
Rank 1
answered on 21 Mar 2013, 04:34 PM
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
0
Ivan Petrov
Telerik team
answered on 26 Mar 2013, 01:33 PM
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.
Tags
GridView
Asked by
Shaun
Top achievements
Rank 1
Answers by
Anton
Telerik team
Tony
Top achievements
Rank 1
Ivan Petrov
Telerik team
Share this question
or