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

Alternating rows color of the RadGridView without using RowFormatting events

5 Answers 261 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ricardo
Top achievements
Rank 1
Ricardo asked on 06 Mar 2019, 08:28 AM

Dear All,

I wanted to alternate the rows in my RadGridView, but the way I searched was using RowFormatting events, which I didn't want to use.

Is that possible?

Best wishes.

5 Answers, 1 is accepted

Sort by
0
Pedro Filipe
Top achievements
Rank 1
answered on 07 Mar 2019, 10:07 AM

hi there (bom dia)

 

you can select in the property builder.

 

but the best way is by the formatting? why not using it?

 

i add a problem with the scroll but this code fix the problem just need to change the colors with yours.

 

private void radGridView1_RowFormatting(object sender, RowFormattingEventArgs e)
{
    if (e.RowElement.IsSelected)
    {
        e.RowElement.GradientStyle = GradientStyles.Solid;
        e.RowElement.BackColor = System.Drawing.Color.PaleGreen;
        e.RowElement.DrawFill = true;
    }
    else
    {
        if (e.RowElement.IsOdd)
        {
            e.RowElement.DrawFill = true;
            e.RowElement.BackColor = Color.FromArgb(230, 230, 250);
        }
        else
        {
            e.RowElement.DrawFill = true;
            e.RowElement.BackColor = Color.White;
 
            e.RowElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);

 

 

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 07 Mar 2019, 12:30 PM
Hello, guys,   

Indeed the RowwFormatting or CellFormatting events are the appropriate solution for customizing the rows/cells in RadGridView. Additional information is available in the following help articles:
https://docs.telerik.com/devtools/winforms/controls/gridview/rows/formatting-rows
https://docs.telerik.com/devtools/winforms/controls/gridview/cells/formatting-cells

However, if you want to enable alternating row color, it can be done by setting two properties: set the EnableAlternatingRowColor property to true and then specify the desired color to the TableElement.AlternatingRowColor

this.radGridView1.EnableAlternatingRowColor = true;
this.radGridView1.TableElement.AlternatingRowColor = Color.Yellow;

I hope this information helps. 

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Ricardo
Top achievements
Rank 1
answered on 08 Mar 2019, 02:18 AM
Hello, my friend.

I'm glad you could answer my question. But I have about five or six hundred radgridviews in my project

If I add this event one by one, it's a huge job.

So I need other solutions
0
Ricardo
Top achievements
Rank 1
answered on 08 Mar 2019, 02:24 AM

Hello, my friend.

Thank you for your answer. It works very well.

But this can only control the color of the alternate row in the RadGridView, and I can control the color of the alternate row if I need another row, as in the following code (DataGridView)

GV. RowsDefaultCellStyle. BackColor = Color. White

GV. AlternatingRowsDefaultCellStyle. BackColor = Color Bisque

What should I do?

Best wishes to you.

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 11 Mar 2019, 11:40 AM
Hello, Ricardo,    

If you need to customize the color of the grid rows, the easiest solution would be to use the CellFormatting/ RowFormatting event:
https://docs.telerik.com/devtools/winforms/controls/gridview/cells/formatting-cells
https://docs.telerik.com/devtools/winforms/controls/gridview/rows/formatting-rows

Depending on the condition for applying the color, you can use one of the following approaches as well:
https://docs.telerik.com/devtools/winforms/controls/gridview/cells/conditional-formatting-cells
https://docs.telerik.com/devtools/winforms/controls/gridview/rows/conditional-formatting-rows
https://docs.telerik.com/devtools/winforms/controls/gridview/cells/formating-examples/style-property

Note that most of the forum threads are reviewed by Telerik representatives and sometimes we address the questions asked by our customers in the forums as well. However, a post in the forum doesn't guarantee you a response from the Telerik support team. Moreover, threads are handled according to license and time of posting, so if it is an urgent problem, we suggest you use a support ticket. Thus, our support staff will gladly assist you. Thank you for your understanding.

I hope this information helps.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
GridView
Asked by
Ricardo
Top achievements
Rank 1
Answers by
Pedro Filipe
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Ricardo
Top achievements
Rank 1
Share this question
or