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

Conditional Formatting

5 Answers 424 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Kristof
Top achievements
Rank 1
Kristof asked on 24 May 2007, 08:47 AM

Hi,

I have a gridview with data, similar to your example gridview on conditional formatting. I copy / pasted the example code for conditional formatting but I don't get it to work properly.
The problem is that there is no initial formatting. The gridview has it's standard look. Only after clicking on a cell that contains the formatting-conditional text, the row gets the correct color. Your example seems to work fine, but I see no differences between that code and mine.

 

radGridView1.CellFormatting += new CellFormattingEventHandler(radGridView1_CellFormatting);  
radGridView1.DataSource = meterObjectValueList;  
radGridView1.Refresh();  
 
GridViewColumn col = radGridView1.MasterGridViewTemplate.Columns.FindByDataField("State");  
ConditionalFormattingObject c1 = new ConditionalFormattingObject("ValueRead", ConditionTypes.Equal, "read"""true);  
c1.RowBackColor = Color.Green;  
c1.RowForeColor = Color.Black;  
col.ConditionalFormattingObjectList.Add(c1);  
ConditionalFormattingObject c2 = new ConditionalFormattingObject("ValueInit", ConditionTypes.Equal, "init"""true);  
c2.RowBackColor = Color.Blue;  
col.ConditionalFormattingObjectList.Add(c2);  
radGridView1.MasterGridViewInfo.UpdateView();  
radGridView1.Refresh(); 

 
Am I missing something?

Ben.

5 Answers, 1 is accepted

Sort by
0
Kiril
Telerik team
answered on 24 May 2007, 11:33 AM
Hi Kristof,

Thank you for bringing this issue to our attention.

I copy-pasted your code into a sample project and ran it, but I could not reproduce the problem. I think the problem might be coming from the handler of the CellFormatting event, but I do not have this piece of the puzzle.

Could you send me a sample project which reproduces the problem you're experiencing, or alternatively, the code in the CellFormatting handler? You can do so in a support ticket.

Thanks in advance.
 

Kind regards,
Kiril
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Kristof
Top achievements
Rank 1
answered on 24 May 2007, 12:30 PM
Thanks for thinking with me!

I found the cause of the problem: the column I use for formatting is displaying enum values. If I use a different column with real string values bound to it, then it actually works.

So, to reproduce the problem, simply add an enum to the datasource and bind it to a column and then try conditional formatting.

Probably the check "IsEqual" doesn't return a match when checking against enums. This could be solved by checking against the enum.ToString();

Cheers,

Ben

p.s. happy holidays
0
Kiril
Telerik team
answered on 28 May 2007, 09:56 AM
Thanks a lot for reporting this issue, Kristof. It will be fixed in the upcoming Service Pack 2. I have updated your Telerik points for the report.

If you have any other questions, please feel free to contact us.


Sincerely yours,
Kiril
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Leadeng Leadeng
Top achievements
Rank 1
answered on 27 Jun 2008, 02:29 AM
Hi, Looks like this problem still exist in 2008.1.619 version of RadControls for winforms.

I'm applying conditional formatiiing on enum column and it does not work.

Srini
0
Kiril
Telerik team
answered on 27 Jun 2008, 12:23 PM
Hi Leadeng Leadeng,

Thank you for writing.

I could not reproduce the issue you are describing. I created a DataTable with two columns, one of them of type int, and the other one of type MyFlag, defined as follows:

    public enum MyFlag  
    {  
        On = 0,  
        Off = 1,  
        Indeterminate = 2  
    } 

This table was then bound to the grid.

Immediately after the databinding, two conditional formatting objects were created and added to the grid as shown in the code below:

            ConditionalFormattingObject c1 = new ConditionalFormattingObject();  
            c1.CellBackColor = Color.Red;  
            c1.ApplyToRow = true;  
            c1.ConditionType = ConditionTypes.Equal;  
            c1.TValue1 = "1";  
            c1.Name = "red";  
 
            ConditionalFormattingObject c2 = new ConditionalFormattingObject();  
            c2.CellBackColor = Color.Blue;  
            c2.ApplyToRow = true;  
            c2.ConditionType = ConditionTypes.Equal;  
            c2.TValue1 = "2";  
            c2.Name = "blue";  
 
            radGridView1.MasterGridViewTemplate.Columns[1].ConditionalFormattingObjectList.Add(c1);  
            radGridView1.MasterGridViewTemplate.Columns[1].ConditionalFormattingObjectList.Add(c2); 

Please replicate the scenario that I tested, and let me know if you experience any issues. Furthermore, do not hesitate to contact us with any other questions you have.

All the best,
Kiril
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
GridView
Asked by
Kristof
Top achievements
Rank 1
Answers by
Kiril
Telerik team
Kristof
Top achievements
Rank 1
Leadeng Leadeng
Top achievements
Rank 1
Share this question
or