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

[Solved] Is that possible to compare two column dynamically by ConditionalFormattingObject, or is there any way to do this?

8 Answers 504 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Joy Shih
Top achievements
Rank 1
Joy Shih asked on 31 Dec 2009, 09:27 AM
Hi,
I want to compare two columns in a RadGrid and change the row color dynamically according to the result,
For example,
Column A  : (DataTime) OrderDate
Column B : (DateTime) DueDate
if(OrderDate > DueDate) the row turns to yellow and the fore color of the cell turns to red,
I have tried to set the TValue1 and TValue2, but it seems only to accept specified value which can't be dynamically assgined.

Is there any way to do this or any wrong could you please point out for me?

Thanks for your reply,
                                           Joy

8 Answers, 1 is accepted

Sort by
0
Accepted
Robert
Top achievements
Rank 1
answered on 31 Dec 2009, 06:11 PM
Hello Joy,

According to this forum post, you need to handle the CellFormatting event, which gives you a greater degree of flexibility in setting styles in response to a more complex condition or more operands than made possible by the conditional formatting feature.

The following code should do something similar to what you have described:
        private void radGridView1_CellFormatting(object sender, Telerik.WinControls.UI.CellFormattingEventArgs e) 
        { 
            // order date > due date 
            if (((int)e.CellElement.RowElement.RowInfo.Cells[0].Value) > ((int)e.CellElement.RowElement.RowInfo.Cells[1].Value)) 
            { 
                e.CellElement.DrawFill = true
                e.CellElement.GradientStyle = GradientStyles.Solid; 
                e.CellElement.BackColor = Color.Yellow; 
                e.CellElement.ForeColor = Color.Red; 
            } 
            else // order date < due date 
            { 
                e.CellElement.ResetValue(VisualElement.ForeColorProperty); 
                e.CellElement.ResetValue(VisualElement.BackColorProperty); 
            } 
        } 

I hope this helps.

- Robert
0
Joy Shih
Top achievements
Rank 1
answered on 02 Jan 2010, 01:44 PM
Hello Robert,

Thank you for your reply, that really can solve my problem.
I have been searched before post, but didn't find that, thanks for your information..

nice to meet you ^^


                          Joy
0
jerry
Top achievements
Rank 1
answered on 09 Feb 2010, 06:11 PM
Robert,
How can I disable a button within the CellFormatting event  if it is a new row the user is trying to add to the grid?
Based on what the user enters in the new row I need to be able to enable and disable the button.
Is CellFormatting the correct event? 

Thank You
Jerry
0
Svett
Telerik team
answered on 10 Feb 2010, 07:50 AM
Hi jerry,

You can changed the background to transperant as it is shown in the following code snippet:

button.Text = "Hello";
button.Size = new Size(100, 100);
 
button.ButtonElement.ButtonFillElement.GradientStyle = Telerik.WinControls.GradientStyles.Solid;
button.ButtonElement.ButtonFillElement.BackColor = Color.Transparent;

If you need help, feel free to write us back.

Kind regards,
Svett
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
0
jerry
Top achievements
Rank 1
answered on 10 Feb 2010, 01:41 PM
Svett,
Thank you for your reply.

Within the CellFormatting event how can I get the button and cast it correctly to be able to use buttonelement?

What event fires when I'm adding a new row within the grid so I can disable the button at that point?

Thank You
0
Martin Vasilev
Telerik team
answered on 15 Feb 2010, 01:11 PM
Hello jerry,

Thank you for writing. You can access the button element in CellFormatting event using e.CellElement.Children collection. You have to follow the element structure.

To handle adding new row event, you can use RowsChanging or CurrentRowChanged .net events. Another option is to use CellBeginEdit event and check if current row is type of GridViewNewRowInfo.

Best wishes,
Martin Vasilev
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.
0
jerry
Top achievements
Rank 1
answered on 15 Feb 2010, 04:21 PM
Martin,
I'm still not following what you are saying.  When I user clicks on "add new row" a new row is added with every field in the grid even a button.  I need to disable that but and leave the rest of the buttons already in the grid alone.  So when I'm in the cellFormatting event how do I know that this cell i'm looking at is from a new row and that it is a button and then be able to disable it?
I'm already using RowsChanging to handle the data from the new row.

Do you have an example demo that I can look at?  Please forgive my lack of understanding this control.

Thank You
0
Martin Vasilev
Telerik team
answered on 18 Feb 2010, 07:19 AM
Hi jerry,

Please, excuse me for the misunderstanding. If you want to disable a command button in the new row you have to use ViewCellFormating event instead CellFormatting. Please, consider the following code as example:

void radGridView1_ViewCellFormatting(object sender, CellFormattingEventArgs e)
{
    GridCommandCellElement commandCell = e.CellElement as GridCommandCellElement;
    if (commandCell != null && commandCell.RowElement is GridNewRowElement)
    {
        RadButtonElement buttonElement = commandCell.Children[0] as RadButtonElement;
        if (buttonElement != null)
        {
            buttonElement.Enabled = false;
        }
    }
}

Let me know if you need additional assistance.

Sincerely yours,
Martin Vasilev
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
Joy Shih
Top achievements
Rank 1
Answers by
Robert
Top achievements
Rank 1
Joy Shih
Top achievements
Rank 1
jerry
Top achievements
Rank 1
Svett
Telerik team
Martin Vasilev
Telerik team
Share this question
or