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

Conditional Formatting Based on Non-blank Date Values

7 Answers 270 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Tom Chien
Top achievements
Rank 1
Tom Chien asked on 19 Oct 2009, 05:07 PM
I'm trying to "Conditionally Format" a Row in a different color whose Date value in a specified Column is equal to a specified value.  I added ConditionalFormattingObject using RadGridView.Columns.Item("Date Column's Came").ConditionalFormattingObjectList.Add method.  I haven't been able to get it to work with comparison values other than blank.

I know I can always manually implement conditional formatting using the RowFormatting or CellFormatting Events.  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.

Telerik 2009Q2 (2009.2.9.729), VS 2005 (v8.0.50727.762 SP.050727-7600), XP SP3 on Core2Duo 2.99GHZ with 3GB.

7 Answers, 1 is accepted

Sort by
0
Martin Vasilev
Telerik team
answered on 23 Oct 2009, 07:16 AM
Hello Tom Chien,

Thank you for contacting as. Conditional formatting for Datetime values should work as the other types. The only requirement is that you have to provide a string value for comparison which is possible to be parsed to DateTime type. Please, take a look at the following code-block:

ConditionalFormattingObject c1 = new ConditionalFormattingObject("Orange", ConditionTypes.Equal, myDate.ToString(), "", false);
c1.RowBackColor = Color.FromArgb(255, 209, 140);
c1.CellBackColor = Color.FromArgb(255, 209, 140);
radGridView1.Columns["ShippedDate"].ConditionalFormattingObjectList.Add(c1);
 
ConditionalFormattingObject c2 = new ConditionalFormattingObject("Green", ConditionTypes.Equal, "16.07.2009", "", false);
c2.RowBackColor = Color.FromArgb(219, 251, 91);
c2.CellBackColor = Color.FromArgb(219, 251, 91);
radGridView1.Columns["OrderDate"].ConditionalFormattingObjectList.Add(c2);

Do not hesitate to contact me again if you have other questions.

Greetings,
Martin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Tom Chien
Top achievements
Rank 1
answered on 23 Oct 2009, 10:32 PM
Yeah, well I knew the Date had to be supplied it had to be a String value since the String type of the TValue1 and TValue2 Parameters / Properties of the ConditionalFormattingObject.New Method / Class.

What I just realized is that it had to include a Time portion, whereas the Date values in my Column were formatted to exclude the Time.

Could you please add a feature where it assumes the Time portion is "12:00 am" if a Date is specified without the Time portion (or at least work with values that conform to the FormatString of the Column (which in this case was set to "{0:MM/dd/yy}"))?  This would be consistent with the CDate Funciton.

Thanks

0
Martin Vasilev
Telerik team
answered on 29 Oct 2009, 07:27 AM
Hello Tom Chien,

Thank you for getting back to me.

Actually, the conditional formatting works when you provide a string in a date-time format without a time part. Please, take a look in the provided example code on the second ConditionalFormattingObject - c2. It has "16.07.2009"  for a value and it works as expected for the values having 12 AM time part.

All the best,
Martin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Tom Chien
Top achievements
Rank 1
answered on 30 Oct 2009, 12:48 AM
O-kaaay?!?

1. "16.07.2009" (i.e. the "dd.MM.yyyy" format) may work in Bulgaria, but here in B.F.E. USA, we have to use "2009.07.16" (i.e. the "yyyy.MM.dd" format) for it to work.  Oh and pssst, the "." (period) date-part delimiter is rarely if ever used here in B.F.E. USA. ;)

2. The fact that it requires one specific format (esp. one so unusual for us weirdos here in B.F.E. USA), when just about any other tool that accepts a date value in string format allows for multiple formats, should be documented which to my knowledge it isn't.

3. You didn't address my "feature request" which was that it should allow you to specify a date filter value in at least the format specified in the "FormatString" Property of your "GridViewDataColumn" Class which in my case was "{0:MM/dd/yy}" not to mention that (as I said in #2) "just about any other tool that accepts a date value in string format allows for multiple formats".



0
Vassil Petev
Telerik team
answered on 05 Nov 2009, 05:38 PM
Hello Tom Chien,

Actually, the format date we provided is an example only. It demonstrates that it is not necessary to provide a time part in the string to make the conditions work.  When applying a condition to the DateTime column, RadGridView is trying to parse the provided string value to DateTime type. This allows for accepting strings in different formats AND still applying the condition to the right cell values.

However, the best way to avoid any confusion when you want to apply a condition through code is to use the DateTime type object and its ToString method. This way you will assure that your string value is in a format according to the CurrentCulture:
 
ConditionalFormattingObject c1 = new ConditionalFormattingObject("Red", ConditionTypes.Equal, myDateTime.ToString(), "", false);

You can find a very simple project that demonstrates all of this as attachment to this message.

To address question #3, yes, this is a nice idea and we will discuss how and when to implement it. I have updated your Telerik Points for it.
 

Greetings,
Vassil
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Tom Chien
Top achievements
Rank 1
answered on 05 Nov 2009, 06:47 PM
1. I realize it's an example.  My point was not that "dd.MM.yyyy" Format (or "yyyy.MM.dd" for me) is the "only Format" the ConditionalFormattingObject allows but that it was the "only Format without a Time portion" it allows and that format being an unusual format (at least in the U.S.) both in use of the "." (period) vs. "/" (slash) delimiter as well as the order of the date parts that "unusual" shortcoming being compounded by the fact that it's not documented.  I saw that you could use ToString (which adds a Time potrion by default - if no Format is specified), but my point was that I should be able to use any format like any other tool that accepts dates as string values.

3. You're welcome.  Thank you for the points and your team for considering this feature request.

0
Martin Vasilev
Telerik team
answered on 11 Nov 2009, 02:42 PM
Hello Tom Chien,

We will make the necessary research in order to improve the discussed feature according the suggestions that you and other customers made. Thank you once again for the feedback.

Greetings,
Martin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
Tom Chien
Top achievements
Rank 1
Answers by
Martin Vasilev
Telerik team
Tom Chien
Top achievements
Rank 1
Vassil Petev
Telerik team
Share this question
or