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

Dynamically changing grid row color at runtime

9 Answers 504 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Randy
Top achievements
Rank 1
Randy asked on 29 Apr 2010, 10:14 PM
Hi,

I have a RadGridView that is using the AlternateRowBackground property to display different colors for every other row (basically odd and even rows).  I also have two RadColorPicker controls on the page that allows the user to be able to select the color they want to use for the odd row and the even row.  When the user selects a color, I want to be able to change the color of the row based on the user's selection. 

The documention seems to indicate that the AlternateRowBackground properly can be set and the color will change, but when I do that in the RadColorPicker event handler, nothing changes on the grid.

Is there a way to change the row colors dynamically based on a user selected value? 

Thanks for your time.
Randy

9 Answers, 1 is accepted

Sort by
0
Accepted
Kalin Milanov
Telerik team
answered on 30 Apr 2010, 12:46 PM
Hi Randy,

 Unfortunately there seems to be a bug causing the grid not refresh its alternate background properly. Calling Rebind() after you set the color is a possible workaround until we provide a fix for this.

Greetings,
Kalin Milanov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Randy
Top achievements
Rank 1
answered on 30 Apr 2010, 05:17 PM
Hi Kalin,

Thanks for the response - using Rebind() as the workaround does the trick for the alternate background property.

Is there a similar method for setting the background row color for the non-alternate rows?  Or is the only solution to use the RowStyle property?

Thanks,
Randy
0
Accepted
Vlad
Telerik team
answered on 03 May 2010, 07:02 AM
Hello Randy,

For the normal rows you can use RowStyle or RowStyleSelector only.

Kind regards,
Vlad
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Randy
Top achievements
Rank 1
answered on 03 May 2010, 12:19 PM
Thanks Vlad - that is what I thought but wanted to confirm.
0
Kamil Massani
Top achievements
Rank 1
answered on 12 Oct 2010, 09:50 PM
Hi Randy,

Can you provide some help on how you changed the colors of the rows in your grid View. I'm trying to do something similar to what you've done.

Thanks,
Kamil
0
Randy
Top achievements
Rank 1
answered on 13 Oct 2010, 02:29 AM
Hi Kamil,

Try something like this:

// alternate row background color
YourGridView.AlternateRowBackground = new SolidColorBrush(Colors.Blue);
  
// standard row background color
var newRowColor = new Style { TargetType = typeof(Telerik.Windows.Controls.GridView.GridViewRow) };
newRowColor.Setters.Add(new Setter(BackgroundProperty, Colors.Green));
YourGridView.RowStyle = newRowColor;
  
// not sure if this line is still needed - the original bug may fixed
YourGridView.Rebind();

Hopefully this is what you were looking for.

Randy
0
Kamil Massani
Top achievements
Rank 1
answered on 13 Oct 2010, 03:05 PM
Thanks Randy, That worked like a charm.

Thanks a lot.
Kamil
0
Rick Mueller
Top achievements
Rank 1
answered on 25 Aug 2011, 03:37 AM
Hello,

HAs this bug been fixed?

thanks
Rick
0
Maya
Telerik team
answered on 30 Aug 2011, 03:09 PM
Hi Rick Mueller,

You may test the functionality in our demos. Once you change the value of a UnitPrice to be less than 30$, the style will be updated.
 

Regards,
Maya
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Tags
GridView
Asked by
Randy
Top achievements
Rank 1
Answers by
Kalin Milanov
Telerik team
Randy
Top achievements
Rank 1
Vlad
Telerik team
Kamil Massani
Top achievements
Rank 1
Rick Mueller
Top achievements
Rank 1
Maya
Telerik team
Share this question
or