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

Conditional formatting

5 Answers 229 Views
GridView
This is a migrated thread and some comments may be shown as answers.
ornus
Top achievements
Rank 1
ornus asked on 15 Aug 2007, 09:54 PM
Is it possible to do conditional formatting based on the property of the value, in addition to the value.

For example, format red if value.Length > 50?

Thank you.

5 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 16 Aug 2007, 04:56 PM
Yes, ornus, this is possible through the CellFormatting event of RadGridView. Here is a code snippet on how to achieve this (we assume you have a custom column of type Point named "Custom"):

this.radGridView1.CellFormatting += new CellFormattingEventHandler(radGridView1_CellFormatting);

void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
{
    if (e.CellElement.ColumnInfo.UniqueName == "Custom")
    {
         Point point = (Point)e.CellElement.Value;
         if (point.Y < 10)
              e.CellElement.ForeColor = Color.Red;
         else
              e.CellElement.ForeColor = Color.Blue;
    }
}     



Let us know if you have other questions.
 
Kind regards,
Jack
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
bradley baker
Top achievements
Rank 1
answered on 23 Mar 2010, 08:22 PM
Can we still access cells via this method in the Q1 2010 version?  When I try it says UniqueName is not a member of Telerik.WinControls.UI.GridViewColumn.
0
Jack
Telerik team
answered on 24 Mar 2010, 03:16 PM
Hello bradley baker,

Yes, you can access the UniqueName property, which is now a property of the GridViewDataColumn. So, you should do a cast. We had to change this, because GridViewColumn is a base column type which is also inherited also from system columns which don't have unique names. Should you have other questions, feel free to contact me.

 

Greetings,
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
bradley baker
Top achievements
Rank 1
answered on 24 Mar 2010, 04:44 PM
Can you give an example.  (VB pref)
0
Jack
Telerik team
answered on 25 Mar 2010, 06:24 PM
Hi bradley,

here is the sample in VB:

Private Sub RadGridView1_CellFormatting(ByVal sender As Object, ByVal e As Telerik.WinControls.UI.CellFormattingEventArgs) Handles RadGridView1.CellFormatting
    Dim column As GridViewDataColumn = TryCast(e.CellElement.ColumnInfo, GridViewDataColumn)
    Dim cell As GridDataCellElement = TryCast(e.CellElement, GridDataCellElement)
    If column IsNot Nothing And column.UniqueName = "Custom" Then
        Dim point As Point = CType(cell.Value, Point)
        If point.Y < 10 Then
            e.CellElement.ForeColor = Color.Red
        Else
            e.CellElement.ForeColor = Color.Blue
        End If
    End If
End Sub

 

Best wishes,
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.
Tags
GridView
Asked by
ornus
Top achievements
Rank 1
Answers by
Jack
Telerik team
bradley baker
Top achievements
Rank 1
Share this question
or