Highlight Group Row

2 posts, 0 answers
  1. Versile
    Versile avatar
    20 posts
    Member since:
    May 2009

    Posted 23 Aug 2009 Link to this post

    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.

    1             AggregateCollection coll = e.Group.Aggregates; 
    2             double max = 0, current = 0; 
    3             foreach (Aggregate agg in coll) 
    4             { 
    5                 switch (agg.FieldName) 
    6                 { 
    7                     case "max"
    8                         max += Convert.ToDouble(agg.Value.ToString()); 
    9                         break
    10                     case "current"
    11                         current += Convert.ToDouble(agg.Value.ToString()); 
    12                         break
    13                 } 
    14             } 
    15             double percentage = 0; 
    16             if (max == 0 && current == 0) 
    17             { 
    18                 percentage = 0; 
    19             } 
    20             else 
    21             { 
    22                 if (max == 0 && current > 0) 
    23                 { 
    24                     percentage = 1.1; 
    25                 } 
    26                 else 
    27                 { 
    28                     percentage = current / max; 
    29                 } 
    30             } 
    31             if (percentage > 0) 
    32             { 
    33
    e.Group.HeaderRow.GridViewInfo.GridViewElement.BackColor = Color.LightGreen;
    37             } 
    38             if (percentage >= .6) // Indicate middle tier (yellow) 
    39             { 
    40                 e.Group.HeaderRow.GridViewInfo.GridViewElement.BackColor = Color.Yellow; 
    41             } 
    42             if (percentage >= .8) // Indicate upper tier (red) 
    43             { 
    44                 e.Group.HeaderRow.GridViewInfo.GridViewElement.BackColor = Color.Red; 
    45             } 
    46             if (percentage > 1.0) // Indicate overbooked (violet) 
    47             { 
    48                 e.Group.HeaderRow.GridViewInfo.GridViewElement.BackColor = Color.Violet; 
    49             } 

  2. Deyan
    Admin
    Deyan avatar
    2039 posts

    Posted 24 Aug 2009 Link to this post

    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.
  3. UI for WinForms is Visual Studio 2017 Ready
Back to Top