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

Apply conditional formatting to another column

4 Answers 224 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Richard Slade
Top achievements
Rank 2
Richard Slade asked on 17 Sep 2010, 09:52 AM
Hi, 

I need to change the font colour of a cell value when I don't have access to CellElement (I understand that in the new version of the grid, this is a problem)

Is it possible to apply conditional formatting to a column based on the value of a different column?

For example: 
If in Row 1, the value of Cell X = 123 then add a conditional formatting object to Cell Y

Thanks
Richard

4 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 22 Sep 2010, 05:19 PM
Hello Richard Slade,

Thank you for this question. Yes, this is possible. Please check the "Grid View - Customize - Formatting with Code" example in our demo application. It demonstrates exactly the described case.

Should you have any further questions, I will be glad to help.

Kind regards, Jack
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
Richard Slade
Top achievements
Rank 2
answered on 22 Sep 2010, 05:46 PM
Thanks Jack, but as I said, I don't have access to the RowElement at this point. 
I need to loop over the Rows in the grid 
For Each row As GridViewRowInfo In Me.GridViewProducts.MasterTemplate.Rows
and therefore only have access to RowInfo.

At the moment, I am applying some conditional formatting... 
If Not .ProductCodeOk Then
    Dim codeFormatter As New ConditionalFormattingObject("product", ConditionTypes.Equal, row.Cells("code").Value.ToString(), "", False)
    codeFormatter.CellForeColor = System.Drawing.Color.Red
    Me.GridViewProducts.Columns("code").ConditionalFormattingObjectList.Add(codeFormatter)
    hasErrors = True
End If
But of course I cannot say... 
If Not .ProductCodeOk Then
    Dim codeFormatter As New ConditionalFormattingObject("product", ConditionTypes.Equal, row.Cells("SOMETHING ELSE").Value.ToString(), "", False)
    codeFormatter.CellForeColor = System.Drawing.Color.Red
    Me.GridViewProducts.Columns("code").ConditionalFormattingObjectList.Add(codeFormatter)
    hasErrors = True
End If
0
Accepted
Jack
Telerik team
answered on 23 Sep 2010, 10:03 AM
Hi Richard Slade,

You can cause RowFormatting event to fire at any point by calling the Update method of GridTableElement or the InvalidateRow method of the row:


Me
.radGridView1.TableElement.Update(GridUINotifyAction.StateChanged)
' or
Me.radGridView1.Rows(5).InvalidateRow()

I hope this helps. 

Sincerely yours,
Jack
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
Richard Slade
Top achievements
Rank 2
answered on 23 Sep 2010, 12:03 PM
Thanks. Used a variant of this and that has worked for me. 
Cheers
Richard
Tags
GridView
Asked by
Richard Slade
Top achievements
Rank 2
Answers by
Jack
Telerik team
Richard Slade
Top achievements
Rank 2
Share this question
or