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

Grid background colour.

7 Answers 876 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
-1
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.
David
Top achievements
Rank 1
commented on 24 Sep 2024, 08:33 PM | edited

I'm trying this approach, but the background is still white. There are only three rows, but the rest of the grid control is white. Here is the code:

this.radGridView1.TableElement.GradientStyle = GradientStyles.Solid;
this.radGridView1.TableElement.GridViewElement.BackColor = Color.LightGray;
this.radGridView1.TableElement.BackColor = Color.LightGray;
this.radGridView1.TableElement.BackColor2 = Color.LightGray;
this.radGridView1.TableElement.BackColor3 = Color.LightGray;
this.radGridView1.TableElement.BackColor4 = Color.LightGray;

 

Nadya | Tech Support Engineer
Telerik team
commented on 26 Sep 2024, 10:35 AM

Hello, David, 

I have checked it on my side and confirm that setting the TableElement.BackColor does change the color to LightGray. 

Maybe there is something different on your side. Can you please specify which is the exact theme that you use? 

Looking forward to your reply.

David
Top achievements
Rank 1
commented on 26 Sep 2024, 02:57 PM

Thanks for the response. The data is retrieved dynamically. I was setting the BackColor before I bound the grid to the data. I have to set the TableElement.BackColor every time I bind the data.

I'm not really using a theme. But, I'm using EnableAlternatingRowColor = true. And now I have these issues below. I have tried to use the radGridView1_RowFormatting event, but it seems to ignore the formatting set in that event:

1) The orange selected row AND cell should be Color.FromArgb(234, 253, 172). 

2) The non-alternate rows should have a white background.

How do I set the backcolor of the selected row, and then the backcolor of the non-selected, non-alternate row?

 

Thanks,

David

 

David
Top achievements
Rank 1
commented on 26 Sep 2024, 06:24 PM

Thanks for your help. I was able to get exactly what I needed using the radGridView1_ViewCellFormatting event.
Nadya | Tech Support Engineer
Telerik team
commented on 30 Sep 2024, 02:00 PM

Hello, David,

Upon reading your latest reply it seems that you managed to get the things done according to your needs by using the ViewCellFormatting event. I am really glad to hear this event is helpful to you. Using formatting events is the right approach when trying to customize colors and look in RadGridView.

If you have any other questions, do not hesitate to contact us.

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