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

Change row color with date value

5 Answers 164 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Tiago
Top achievements
Rank 2
Tiago asked on 15 Oct 2009, 02:37 PM
Dear friends,

I have a read only RadGridView with several columns. One of those columns is a date, and i want to change the backcolor of the rows that have the date smaller than today's data.

Can you help me?

Thanks in advance.

5 Answers, 1 is accepted

Sort by
0
Tom Chien
Top achievements
Rank 1
answered on 15 Oct 2009, 10:09 PM
Well, you'd think you could do it by adding a ConditionalFormattingObject using RadGridView.Columns.Item(your date column's name / index).ConditionalFormattingObjectList.Add method.  I haven't been able to get it to work with comparison values other than blank.  So how do you do it, Telerik?  Inquiring minds want to know.

Telerik 2009Q2 (2009.2.9.729), VS 2005 (v8.0.50727.762 SP.050727-7600), XP SP3 on Core2Duo 2.99GHZ with 3GB.
0
Tom Chien
Top achievements
Rank 1
answered on 16 Oct 2009, 04:25 PM
You can always manually implement conditional formatting using the CellFormatting Event.  However, that means the user can't add, edit or delete the formatting (unless you also implement your own Conditional Formats Editor) it and it can't be saved / loaded by SaveLayout / LoadLayout (unless you manually add / remove-interpret it before / after the calls to SaveLayout / LoadLayout ).  Getting the ConditionalFormattingObject to support comparing non-blank Date values would still be the ideal solution.  What say ye, Telerik
0
Tiago
Top achievements
Rank 2
answered on 16 Oct 2009, 04:35 PM
Hey Tom,

Thanks for your help at this time.

I've been able to do some DataBase side validations, and, when my column with the name "state" comes with the int value 5, i must set that row background to red. I'm kinda confused right now, could you give me an example on how could i do that?

Thanks again.
0
Accepted
Tom Chien
Top achievements
Rank 1
answered on 16 Oct 2009, 05:04 PM
I thought you were trying to change row colors based on a date value of a column of those rows.  The only problem I was having was with Conditional Formatting based on non-blank date values. 

You should be able to do what you just described by doing something like the following:

with oMyRadGrid.MasterGridViewTemplate 
    Dim oHiLtSt5RowsFmt As New ConditionalFormattingObject("HiLtSt5RowsFmt", ConditionTypes.NotEqual, "5"""True
    oHiLtSt5RowsFmt.CellBackColor = Red 
  .Columns.Item("MyStateColumnHeaderName").ConditionalFormattingObjectList.Add(oHiLtSt5RowsFmt) 
end with ' -- oMyRadGrid.MasterGridViewTemplate 
 

0
Tiago
Top achievements
Rank 2
answered on 19 Oct 2009, 10:17 AM
Dear Tom,

Thanks once again.

Please take a look at this ... check the last post! :)

Tags
GridView
Asked by
Tiago
Top achievements
Rank 2
Answers by
Tom Chien
Top achievements
Rank 1
Tiago
Top achievements
Rank 2
Share this question
or