8 Answers, 1 is accepted
Thank you for writing.
Yes, it is possible to use conditional formatting on a boolean column. The following sample demonstrates how to do this:
DataTable table = new DataTable(); |
table.Columns.Add("ID"); |
table.Columns.Add("Name"); |
table.Columns.Add("Boolean"); |
for (int i = 0; i < 5; i++) |
table.Rows.Add(i, "Row " + i, true); |
this.radGridView1.MasterGridViewTemplate.AutoGenerateColumns = false; |
this.radGridView1.Columns.Add(new GridViewTextBoxColumn("ID")); |
this.radGridView1.Columns.Add(new GridViewTextBoxColumn("Name")); |
GridViewBooleanColumn column = new GridViewBooleanColumn("Boolean"); |
this.radGridView1.Columns.Add(column); |
this.radGridView1.DataSource = table; |
this.radGridView1.RightToLeft = RightToLeft.Yes; |
ConditionalFormattingObject obj = new ConditionalFormattingObject("Condition", ConditionTypes.Greater, "1", "", false); |
obj.CellBackColor = Color.Red; |
this.radGridView1.Columns[2].ConditionalFormattingObjectList.Add(obj); |
this.radGridView1.GridElement.Update(false); |
In case you have additional questions, don't hesitate to contact us.
All the best,
Jack
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
We tested the solution sent to you and found an issue related to checkbox columns. Unfortunately the conditional formatting does not evaluate these kinds of columns correctly. We will fix this in the upcoming release in December.
As a workaround I can offer you to use the CellFormatting event. Refer to the sample code below:
void radGridView1_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e) |
{ |
if (e.CellElement is GridCheckBoxCellElement) |
{ |
if ((bool)e.CellElement.Value) |
{ |
e.CellElement.DrawFill = true; |
e.CellElement.BackColor = Color.Red; |
} |
else |
{ |
e.CellElement.DrawFill = false; |
} |
} |
} |
Please, tell us if this solution helps.
Best wishes,
Jack
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Nevermind.... I figured it out.
I need the row color changed if the marker was set to false which means I needed to use:
ConditionalFormattingObject
obj = new ConditionalFormattingObject("Complete", ConditionTypes.Less, "1", "", true);
Although a little note for Telerik, this seems a little confusing for use with a boolean columns. Is there a way in the future when coding in manually like this, to have the ConditionalFormattingObject overloaded to accept a bool as a value rather than 2 strings? Just a thought.
_________________________________________________________
Correction again.... the above code does indeed change the color of the rows.... but but all my rows were false until, so I didn't see this until now. So now I have a mix of T & F in the same column, and with the above code, all the rows are colored when only the false rows are to be colored... I even tried adding another line to evaluated for true, but that didn't help... its like all or nothing.....
Thank you for writing us.
Unfortunately, this issue still exists in the current latest release of RadGridView. We will address it in the Q1 2008 release. We will revise our API and will add such an overload to the ConditionalFormattingObject.
Thank you for your suggestions.
Do not hesitate to contact us, if you have other questions.
All the best,
Jack
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Did you fix this for the 2008 Q1 ?
Guy
Thank you for this question.
Actually, we decided to leave the ConditionalFormattingObject constructors as they are. There is no overload that takes a boolean property as an argument. Nevertheless, the conditional formatting works fine with boolean columns in our latest release. You could also process the CellFormatting event as an alternative solution to this issue.
I strongly recommend updating to the latest release of RadControls. If you need any further assistance, I will be glad to help you.
Kind regards,
Jack
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.