Conditions are if value of cell is Between 0.23 and 3.41, set background color to Yellow.
This works well until in one column the cell value >= 10.0 and it starts to highlight the cell again.
5 Answers, 1 is accepted
Thank you for contacting us.
If you want to apply one conditional formatting rule to two or more columns, you need to use ExpressionFormattingObject. The expression could refer to data from more than one column. Please take a look at the following example:
ExpressionFormattingObject expressionCondition =
new
ExpressionFormattingObject(
"MyCondition"
,
"UnitPrice > 0.23 AND Price > 0.23 AND UnitPrice < 3.41 AND Price < 3.41"
,
true
);
expressionCondition.RowBackColor = Color.Yellow;
this
.radGridView1.Columns[
"Price"
].ConditionalFormattingObjectList.Add(expressionCondition);
You can find more information about ExpressionFormattingObject in our help documentation, section Expression based formatting objects.
I attached a sample demo project to demonstrates you the formatting.
Should you have further questions, I would be glad to help.
Regards,
Ralitsa
Telerik
Hi,
this sample works ok, but how can I use functions in expression? if I make expression like:
TRIM(TextBoxColumn)='test' - i got an exception
Thanks
Alex
Hello Alex,
Indeed, using TRIM() expressions via code results in an exception. I have tested the same operation through "Conditional Formatting Rules Manager" form, setting the following expression: TRIM(ContactName) = 'Maria Anders' and it worked OK. It turns out that TRIM() expressions are not parsed correctly when they are set in code.
Therefore, I have logged a bug in our feedback portal. You can track its progress, subscribe for status changes and add your comments on the following link - feedback item.
I have also updated your Telerik points.
As a workaround you could subscribe to RadGridView.CellFormatting event and format your cells as follows:
private void RadGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
{
if (e.Row is GridViewDataRowInfo && e.Column.Name == "ContactName")
{
if (e.CellElement.Text.Trim() == "Maria Anders")
{
e.CellElement.DrawFill = true;
e.CellElement.GradientStyle = GradientStyles.Solid;
e.CellElement.BackColor = Color.Aqua;
}
else
{
e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
}
}
else
{
e.CellElement.ResetValue(LightVisualElement.DrawFillProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.GradientStyleProperty, ValueResetFlags.Local);
e.CellElement.ResetValue(LightVisualElement.BackColorProperty, ValueResetFlags.Local);
}
}
In this scenario if there is a cell with "Text.Trim() == 'Maria Anders'", the CellBackColor will be set to Aqua.
I hope you find this information useful.
Regards,
Dimitar
Progress Telerik
Hi Dimitar,
on my side it does not work even with Conditional Formatting Rules Manager, it can accept expression, but apply formating only to one cell, .e.g. try condition like Trim(ContactTitle) = 'Accounting Manager'
Anyway, hope we get enough votes and bug will be fixed
Alex
Hello Alex,
I could not reproduce your experience with Conditional Formatting Rules Manager. Please see the attachment. Feel free to use the provided workaround until we fix the bug. In case the issue persists please open up a support ticket and send us your project so that we can further test it.
Regards,
Dimitar
Progress Telerik