This is a migrated thread and some comments may be shown as answers.

Conditional Formatting on a booleanColumn

8 Answers 377 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Chris Castle
Top achievements
Rank 1
Chris Castle asked on 13 Nov 2007, 04:33 PM
Is it possible to use Conditional Formatting on a BooleanColumn.  I can't get it to work so I must be missing something.

8 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 14 Nov 2007, 12:12 PM
Hello Chris Castle,

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
0
Eric
Top achievements
Rank 1
answered on 27 Nov 2007, 07:20 PM
This does not seem to work for me.  I even tried to use the RadGridView Conditional Formatting demo and I can't seem to get the formatting to work for the "Bool" column.  Can you tell me what the condition settings should be for the demo to get it to work?
0
Jack
Telerik team
answered on 28 Nov 2007, 06:00 PM
Hello Eric,

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
0
Tim
Top achievements
Rank 1
answered on 26 Feb 2008, 04:30 AM
has this issue been resolved?  I'm using the Q3 release and I'm having the same issue.

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.....

0
Jack
Telerik team
answered on 26 Feb 2008, 11:24 AM
Hello Tim,

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
0
Guy
Top achievements
Rank 1
answered on 20 Oct 2008, 03:13 PM
Hi ,
Did you fix this for the 2008 Q1 ?

Guy
0
Jack
Telerik team
answered on 24 Oct 2008, 11:10 AM
Hello 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.
0
Skurken
Top achievements
Rank 1
answered on 29 Jun 2009, 11:25 AM
Nvm :)
Tags
GridView
Asked by
Chris Castle
Top achievements
Rank 1
Answers by
Jack
Telerik team
Eric
Top achievements
Rank 1
Tim
Top achievements
Rank 1
Guy
Top achievements
Rank 1
Skurken
Top achievements
Rank 1
Share this question
or