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

DataTrigger Compare Column

3 Answers 183 Views
GridView
This is a migrated thread and some comments may be shown as answers.
John Giblin
Top achievements
Rank 1
John Giblin asked on 19 Mar 2011, 02:34 AM
I want to Compare 2 columns in a a RadGridView to set the style of the cell.  I saw the example where you are comparing to a static value, but is there a way to compare it to another column.  Basically I want to see if 2 columns are equal. If not, make the font bold and red.

3 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 21 Mar 2011, 10:59 AM
Hello John Giblin,

As the item parameter in the SelectStyle method is your business object, you may compare two properties like follows:

public override Style SelectStyle(object item, DependencyObject container)
        {
            if (item is Club)
            {
                Club club = item as Club;
                if (club.StadiumCapacity == club.StadiumCapacity1)
                {
                    ....
                                }
            }
            return null;
        }

I am sending you a sample project illustrating the proposed solution. Let me know whether it corresponds to your requirements.
  


Best wishes,
Maya
the Telerik team
0
John Giblin
Top achievements
Rank 1
answered on 20 Apr 2011, 05:44 PM
Worked great.  The only issue that I had was if I defined a background color in GridViewDataColumn it would not override it

Also, what I was not crazy about is creating a class for each column I needed to have a conditional style.  I had 5 columns that I needed some conditional style for. Is there a way to iterate through the rows and change the style
0
Maya
Telerik team
answered on 22 Apr 2011, 10:18 AM
Hi John Giblin,

May you provide a bit more details about the scenario you want to accomplish ? Why do you want to define a Background for the whole column - may you try to set this background property in the styles for the CellStyleSelector ?
As for you second requirement, do you want to achieve something like style selector for each separate column ? Is it not appropriate to use a RowStyleSelector ? Considering the iteration through rows, it would be better to use the Items collection of the grid, instead of working with the UI elements.
 

Greetings,
Maya
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
John Giblin
Top achievements
Rank 1
Answers by
Maya
Telerik team
John Giblin
Top achievements
Rank 1
Share this question
or