Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

How to: Format Unique or Duplicate Values, Blank Cells and Formula Errors

  • 2 minutes to read

This example demonstrates how to specify the rule that highlights unique or duplicate values, formula errors, etc.

  1. To create a new conditional formatting rule represented by the SpecialConditionalFormatting object, access the collection of conditional formats from the Worksheet.ConditionalFormattings property and call the ConditionalFormattingCollection.AddSpecialConditionalFormatting method. Pass the following parameters:

  2. Specify formatting options to be applied to cells if the condition is true, using the ISupportsFormatting.Formatting property of the SpecialConditionalFormatting object.

Note

Transparency is not supported in conditional formatting.

To remove the SpecialConditionalFormatting object, use the ConditionalFormattingCollection.Remove, ConditionalFormattingCollection.RemoveAt or ConditionalFormattingCollection.Clear methods.

View Example

// Create the rule to identify unique values in cells A2 through A15. 
SpecialConditionalFormatting cfRule = worksheet.ConditionalFormattings.AddSpecialConditionalFormatting(worksheet.Range["$A$2:$A$15"], ConditionalFormattingSpecialCondition.ContainUniqueValue);
// Specify formatting options to be applied to cells if the condition is true.
// Set the background color to yellow.
cfRule.Formatting.Fill.BackgroundColor = Color.FromArgb(255, 0xFA, 0xF7, 0xAA);

The image below shows the result (the workbook is opened in Microsoft® Excel®). Unique values in the list of authors are highlighted in yellow.

SpecialConditionalFormatting