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

Highlight Group Row

1 Answer 112 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Versile
Top achievements
Rank 1
Versile asked on 23 Aug 2009, 06:18 AM
I'm trying to highlight my group rows in a grid based on their aggregate values. For example I have values for Max and Current, and depending on the percentage of values I would like to highlight the group header yellow/red/violet/green as appropriate. The attached code soomewhat works except it highlights the entire grid green, any help you can provide. (This is in the GroupSumaryEvaluate event.

            AggregateCollection coll = e.Group.Aggregates; 
            double max = 0, current = 0; 
            foreach (Aggregate agg in coll) 
            { 
                switch (agg.FieldName) 
                { 
                    case "max"
                        max += Convert.ToDouble(agg.Value.ToString()); 
                        break
                    case "current"
                        current += Convert.ToDouble(agg.Value.ToString()); 
                        break
                } 
            } 
            double percentage = 0; 
            if (max == 0 && current == 0) 
            { 
                percentage = 0; 
            } 
            else 
            { 
                if (max == 0 && current > 0) 
                { 
                    percentage = 1.1; 
                } 
                else 
                { 
                    percentage = current / max; 
                } 
            } 
            if (percentage > 0) 
            { 
e.Group.HeaderRow.GridViewInfo.GridViewElement.BackColor = Color.LightGreen;
            } 
            if (percentage >= .6) // Indicate middle tier (yellow) 
            { 
                e.Group.HeaderRow.GridViewInfo.GridViewElement.BackColor = Color.Yellow; 
            } 
            if (percentage >= .8) // Indicate upper tier (red) 
            { 
                e.Group.HeaderRow.GridViewInfo.GridViewElement.BackColor = Color.Red; 
            } 
            if (percentage > 1.0) // Indicate overbooked (violet) 
            { 
                e.Group.HeaderRow.GridViewInfo.GridViewElement.BackColor = Color.Violet; 
            } 

1 Answer, 1 is accepted

Sort by
0
Deyan
Telerik team
answered on 24 Aug 2009, 09:01 AM
Hi Versile,

Thanks for writing and for the provided code snippet.

Based on what I have seen from your code, I assume that the undesired behavior that you experience is related to the fact that you set the BackColor property of the GridViewElement which, basically, changes the background color of the whole RadGridViewElement.

If you wish to change the background color of the Header Row, you should use the following approach:

void radGridView1_GroupSumaryEvaluate(object sender, GroupSummaryEvaluationEventArgs e)  
{  
     e.Group.HeaderRow.VisualElement.DrawFill = true;  
     e.Group.HeaderRow.VisualElement.BackColor = Color.Red;  

As you can see, I set the DrawFill property of the Header Row' Visual Element (the element that represents the visual part of a header row) in order to make the fill visible (initially the fill is hidden because of some performance considerations). I also set the BackColor property of the VisualElement according to my preferences. You should also note that, if you want to have a gradient background you should also use the BackColor2, BackColor3 and BackColor4 properties to build your gradient. The NumberOfColors property defines how many colors are used for your gradient. The maximum number is 4.

If you do not want to have a gradient background, you should only use the BackColor property and set the GradientStyle property to Solid.

I hope this is helpful. Do not hesitate to write back if you need further assistance.

Greetings,
Deyan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
GridView
Asked by
Versile
Top achievements
Rank 1
Answers by
Deyan
Telerik team
Share this question
or