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; | |
} |