Alternating and Selected Row color issues

8 posts, 1 answers
  1. Aaron
    Aaron avatar
    7 posts
    Member since:
    Aug 2012

    Posted 01 Mar 2011 Link to this post

    First, I am unable to get alternating row color to work. I have implemented it like this article says (http://www.telerik.com/help/winforms/gridview-styling-and-appearance-alternating-row-color.html) but all the columns remain white. Can you please tell me in which method to put

    CType
    (Me.RadGridView1.TableElement, GridTableElement).AlternatingRowColor = Color.Yellow

    I have tried in the form load and other events of the grid, like row formatting.


    Also, I am trying to implement the hover over and selected row color but when I set the Row Formatting like the following article (http://www.telerik.com/community/forums/winforms/gridview/change-color-of-selected-row-in-gridview.aspx) the row is highlighted with orange and of the two columns in the row, the one that is not selected is the correct color, blue. This changes when I click on the other cell in the row. Furthermore, the cell that is blue still has an orange border.
  2. Answer
    Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 01 Mar 2011 Link to this post

    Hello Aaron,

    You can do both of those things using RowFormatting, like so:
    void radGridView1_RowFormatting(object sender, RowFormattingEventArgs e)
    {
        if (e.RowElement.RowInfo.IsCurrent)
        {
            e.RowElement.GradientStyle = GradientStyles.Solid;
            e.RowElement.BackColor = Color.Orange;
            e.RowElement.DrawFill = true;
        }
        else if (e.RowElement.RowInfo.Index % 2 == 0)
        {
            e.RowElement.GradientStyle = GradientStyles.Solid;
            e.RowElement.BackColor = Color.Yellow;
            e.RowElement.DrawFill = true;
        }
        else
        {
            e.RowElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
            e.RowElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
            e.RowElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
        }
    }

    Now i cannot find the exact link but somewhere in the documentation is stated that whenever possible, it is better to implement alternating row colors as row formatting to improve performance.

    Hope this helps, if you have any other questions or comments, please let me know,

    Best Regards,
    Emanuel Varga

    Telerik WinForms MVP
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Aaron
    Aaron avatar
    7 posts
    Member since:
    Aug 2012

    Posted 02 Mar 2011 Link to this post

    Yes that does work, thanks. Though now, instead of doing it programmically, I am trying to use a edited theme. I have done the following but the theme still does not get applied.

    ThemeResolutionService.LoadPackageResource("DPControls.MitchellTheme.tssp")
    ThemeResolutionService.ApplicationThemeName = "MitchellTheme"

    (I have also tried using ThemeResolutionService.LoadPackageFile())


    Could the problem be that I am putting this in the constructor for the User Control that inherits from the RadGridView?
  5. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 02 Mar 2011 Link to this post

    Hello again Aaron,

    If you want to use a custom theme, you can just apply it once in your main form, and all other controls will use that theme.
    For more info on custom themes please take a look at this article.

    Hope this helps, if you have any other questions or comments, please let me know,

    Best Regards,
    Emanuel Varga
  6. Eric
    Eric avatar
    24 posts
    Member since:
    Jul 2011

    Posted 16 Sep 2011 Link to this post

    My application does use a application level linked theme.  My theme is a modified version of the Office 2010-silver theme.  I have hunted and hunted and expected to find some kind of property under the radGridTable->radGridRowElement (from memory) but I cannot find an AlternatingRowColor (or similar property) anywhere.  I see all kinds of other gee-wiz types of properties except this one... which is ironic since I would think this is one of the most elemental styles you would put on a table grid.  

    In any case, I am able to apply the alternating row property (via link above) but would really prefer to apply it to my app-level theme.  Can someone enlighten me as to where exactly in Visual Style Builder I can find this?
  7. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 21 Sep 2011 Link to this post

    Hi Eric,

    Thank you for writing.

    In order to enable alternating row color you should use EnableAlternatingRow property:
    this.radGridView1.EnableAlternatingRowColor = true;

    Then you have two choices to set the color in your theme or through code by using AlternatingRowColor property:
    this.radGridView1.GridElement.AlternatingRowColor = Color.Red;

    To set it in your theme, just use the same property in Visual Style Builder. Please take a look at the attached screenshot. 

    Hope this helps. Let me know if you have any additional questions.

    All the best,
    Martin Vasilev
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  8. Eric
    Eric avatar
    24 posts
    Member since:
    Jul 2011

    Posted 21 Sep 2011 Link to this post

    Ahhh, that was it, THANKS!  For me the reason I could not find it was that little filter drop down you pointed out.  It kept hiding it in the style designer.  Just as general feedback, I would propose that in the future that you add a new control structure (left pane under TableElement).... something like GridAlternatingRowElement or similar so that this is much easier to find and edit.  This would also allow you to use a repository item.

    Also, there appears to be a bug in the preview as it never applies the alternating row color.  However, the setting did take in my app.
  9. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 26 Sep 2011 Link to this post

    Hello Eric,

    Thank you for your suggestion. We will consider if there is an easier way to expose the AlternatingRowColor property in Visual Style Builder for the future.

    As to the preview, it is not shown because the default value for EnableAlternatingColor property is false. Since it is not a RadProperty you cannot access it directly into the grid's element structure. However, for preview proposes, you can open RadControlSpy in Visual Style Builder and use ElementTree.Control to access EnableAlternatingColor and change its value.

    Do not hesitate to contact us again if you need any additional assistance.

    Greetings,
    Martin Vasilev
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top
UI for WinForms is Visual Studio 2017 Ready