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

Row Formatting

1 Answer 315 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Mickey Keenan
Top achievements
Rank 1
Mickey Keenan asked on 12 Jun 2007, 05:25 PM
I have issues setting row formatting for a particular row.  I tried using the RowFormatting event to look at the underlying data item, and compare it to another value.  Based off of that I set the e.RowElement.BackColor to either white or grey.  The problem is that neither one actually shows until I select the row.  Once I select it I get the correct background color until I select another row.

Is there something I am missing...

1 Answer, 1 is accepted

Sort by
0
Kiril
Telerik team
answered on 13 Jun 2007, 12:18 PM
Hello Mickey,

Thank you for the question.

Before we get to your question, we need to describe the scenarios where conditional formatting is preferable over row formatting. Basically, Row formatting is meant to be used only in scenarios conditional formatting can't handle.

As far as I understood your question, you need to send the back color of a row depending on the value in a cell. This is a task that can easily be handled using conditional formatting.

Here's a code snippet that illustrates the approach:

//initialize the conditional formatting objects  
ConditionalFormattingObject c1 = new ConditionalFormattingObject("white rule", ConditionTypes.Equal, "USA"""true);  
c1.RowBackColor = Color.White;  
c1.RowForeColor = Color.Black;  
 
ConditionalFormattingObject c2 = new ConditionalFormattingObject("gray rule", ConditionTypes.NotEqual, "USA"""true);  
c2.RowBackColor = Color.Gray;  
c2.RowForeColor = Color.Black;  
 
//add the formatting conditions to the column  
radGridView1.MasterGridViewTemplate.Columns.FindByDataField("Country").ConditionalFormattingObjectList.Add(c1);  
radGridView1.MasterGridViewTemplate.Columns.FindByDataField("Country").ConditionalFormattingObjectList.Add(c2);  
 
//update the grid with the conditional formatting  
radGridView1.MasterGridViewInfo.UpdateView(); 

You can insert the code above in the handler of the Load event of the Form, for example.

Please let me know whether this solution works for you. We do appreciate your feedback, as it helps us prioritize our work, and highlights aspects of our controls we need to improve on. Thanks again.

 
Regards,
Kiril
the Telerik team

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