With the release of version 1.3, there's no doubt that SuperGridView has the most robust and flexible conditional formatting capabilities when compared to other .NET grid controls on the market. It also looks cool as you can see from the screenshot below.
Here's the simple question: How hard is it implement this?
Well, SuperGridView makes it very very easy. Let's go through the process.
In order, to apply conditional formatting with color scales we must define a group of cells and associate with a specific color scale. This normally takes three easy steps.
Step 1. Enable Conditional Formatting and Create the Conditional Formatting group
SuperGridView has a class which wraps this entire functionality. The class is defined within the DataFieldArea of the grid and it's name is ConditionalFormattingGroup. You can use it in the following way:
grid.DataFieldArea.ConditionalFormattingEnabled = true;
DataFieldArea.ConditionalFormattingGroup cfGroup = new DataFieldArea.ConditionalFormattingGroup();
cfGroup.SetConditionalFormattingColorScale(GridCellCFColorScale.GREEN_TO_RED);
The SetConditionalFormattingColorScale method allows you to select one of the built-in color scales. If you prefer to create your own you can use the SetCustomConditionalFormattingColorScale method which simply takes an array of one hundered colors which define the scale.
Step 2. Add the group to the grid's DataFieldArea and assign in a name
This is just a single line of code which basically says: "Hey, SuperGridView, this is my ConditionalFormattingGroup and for you this is its name"
grid.DataFieldArea.ConditionalFormattingGroups.Add("mygroup", cfGroup);
Step 3. Assign grid cells to the conditional formatting group
SuperGridView allows you to add individual cells to a group, as well as entire rows and columns. This is done by calling the methods SetCellConditionalFormattingGroup or SetItemConditionalFormattingGroup for individual cells and for columns/rows respectively.
grid.DataFieldArea.SetCellConditionalFormattingGroup(gridCell, "mygroup");
grid.DataFieldArea.SetItemConditionalFormattingGroup(rowItem, "mygroup");
The following code will create a new conditional formatting group and fill it with a the selected cells:
private void buttonConditionalFormatSelectedCells_Click(object sender, EventArgs e)
{
grid.DataFieldArea.ConditionalFormattingGroups.Clear();
DataFieldArea.ConditionalFormattingGroup cfGroup = new DataFieldArea.ConditionalFormattingGroup();
cfGroup.SetConditionalFormattingColorScale(GridCellCFColorScale.GREEN_TO_RED);
grid.DataFieldArea.ConditionalFormattingGroups.Add("mygroup", cfGroup);
foreach (GridCell cell in grid.DataFieldArea.SelectedCells)
{
grid.DataFieldArea.SetCellConditionalFormattingGroup(cell, "mygroup");
}
}