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

[Solved] Row coloring by value in one column

1 Answer 128 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Nic
Top achievements
Rank 1
Nic asked on 10 Sep 2009, 05:07 PM
Hi,

Suppose I had a list of records, where each record = {item name, description, price}, sorted by price and displayed in a RadDataGrid.
I'd like for all the rows of identical price to be styled in the same color. something like:

ItemA, DescriptionA, 100.99    > row color=red
ItemB, DescriptionB, 100.99    > row color=red
ItemC, DescriptionC, 77.99     > row color=green
ItemD, DescriptionD, 77.99     > row color=green
ItemE, DescriptionE, 45.99     > row color=yellow
ItemF, DescriptionF, 42.99     > row color=orange

The row colors would be in some matrix {red, green, yellow, orange, blue, purple}.

As each group is identified, the next color, is picked. When we run out of colours, then just use some default.

Even better if it would be some style and not just a color.

How might I go about doing something like this.

Thanks!
Nic










ItemA, DescriptionA, 100.99

ItemA, DescriptionA, 100.99





1 Answer, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 11 Sep 2009, 09:47 AM
Hi Nic,

You can attach to the RowLoaded event, cast e.DataElement to your business object type, read the relevant information from the business object and style the row in any way you want. Something like this:

using System.Windows.Controls; 
using System.Windows.Media; 
using Telerik.Windows.Controls.GridView; 
 
namespace TicketID_240045_CellBackgroundBaseOnAValue 
    public partial class MainPage : UserControl 
    { 
        public MainPage() 
        { 
            this.InitializeComponent(); 
            this.playersGrid.ItemsSource = Club.GetPlayers(); 
        } 
 
        private void OnRowLoaded(object sender, RowLoadedEventArgs e) 
        { 
            var player = e.DataElement as Player; 
            if (player != null
            { 
                if(player.Number == 9) 
                { 
                    e.Row.Background = new SolidColorBrush(Colors.Red); 
                } 
                // etc. 
            } 
        } 
    } 

I hope this helps.

Regards,
Ross
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
Nic
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Share this question
or