Alternating rows color of the RadGridView without using RowFormatting events

6 posts, 0 answers
  1. Ricardo
    Ricardo avatar
    22 posts
    Member since:
    Dec 2018

    Posted 06 Mar 2019 Link to this post

    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.

  2. Pedro Filipe
    Pedro Filipe avatar
    8 posts
    Member since:
    Jan 2019

    Posted 07 Mar 2019 in reply to Ricardo Link to this post

    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);

     

     

  3. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3758 posts

    Posted 07 Mar 2019 Link to this post

    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.
  4. Ricardo
    Ricardo avatar
    22 posts
    Member since:
    Dec 2018

    Posted 07 Mar 2019 in reply to Pedro Filipe Link to this post

    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
  5. Ricardo
    Ricardo avatar
    22 posts
    Member since:
    Dec 2018

    Posted 07 Mar 2019 in reply to Dess | Tech Support Engineer, Sr. Link to this post

    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.

  6. Dess | Tech Support Engineer, Sr.
    Admin
    Dess | Tech Support Engineer, Sr.  avatar
    3758 posts

    Posted 11 Mar 2019 Link to this post

    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.
Back to Top