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

Alternating and Selected Row color issues

7 Answers 202 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Aaron
Top achievements
Rank 1
Aaron asked on 01 Mar 2011, 09:48 PM
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.

7 Answers, 1 is accepted

Sort by
0
Accepted
Emanuel Varga
Top achievements
Rank 1
answered on 01 Mar 2011, 11:31 PM
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
0
Aaron
Top achievements
Rank 1
answered on 02 Mar 2011, 06:19 PM
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?
0
Emanuel Varga
Top achievements
Rank 1
answered on 03 Mar 2011, 05:51 AM
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
0
Eric
Top achievements
Rank 1
answered on 16 Sep 2011, 07:19 PM
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?
0
Martin Vasilev
Telerik team
answered on 21 Sep 2011, 03:45 PM
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 >>

0
Eric
Top achievements
Rank 1
answered on 21 Sep 2011, 04:35 PM
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.
0
Martin Vasilev
Telerik team
answered on 26 Sep 2011, 02:42 PM
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 >>

Tags
GridView
Asked by
Aaron
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Aaron
Top achievements
Rank 1
Eric
Top achievements
Rank 1
Martin Vasilev
Telerik team
Share this question
or