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

Comparing date in Conditional Formatting

2 Answers 473 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Gourangi
Top achievements
Rank 1
Gourangi asked on 19 Apr 2008, 10:31 AM
Hi,

I am having problem with conditional formatting feature of telerik reporting for windows application.

(.net framework 2.0 language visual basic 8 and operating system windows xp pro)

I am comparing a datafield and a variable date value and based on that it should filter backcolor of particular textbox which is placed dynamically in detail section of the report.

'FormattingRule1.Filters.AddRange(New Telerik.Reporting.Data.Filter() {New Telerik.Reporting.Data.Filter("=CDate(Fields.S001)", CType(Telerik.Reporting.Data.FilterOperator.GreaterThan, Telerik.Reporting.Data.FilterOperator), "=CDate(""00:07:49"")")})

This is hardcodead things which works fine but if i write these code (below), it throws me an error "Object reference not set to an instance of an object."

Here tItem is a dynamic telerik's reporting textbox
dt.Columns(i).ColumnName is a particular ColumnName which has datetime value and datatype is varchar

    Dim FormattingRule1 As Telerik.Reporting.Drawing.FormattingRule = New Telerik.Reporting.Drawing.FormattingRule
               
    FormattingRule1.Filters.AddRange(New Telerik.Reporting.Data.Filter() {New Telerik.Reporting.Data.Filter("=CDate(""" + averageTime + """)", CType(Telerik.Reporting.Data.FilterOperator.GreaterOrEqual, Telerik.Reporting.Data.FilterOperator), "=CDate(Fields." + dt.Columns(i).ColumnName + ")")})
   
    FormattingRule1.Style.BackgroundColor = System.Drawing.Color.Chocolate
   
    tItem.ConditionalFormatting.AddRange(New Telerik.Reporting.Drawing.FormattingRule() {FormattingRule1})

In short if i replace dt.Columns(i).ColumnName with hardcoaded column name like =CDate(Fields.S001) is not throwing me any error.

It should not be like this.

Help me out.

Thanks

2 Answers, 1 is accepted

Sort by
0
Gourangi
Top achievements
Rank 1
answered on 21 Apr 2008, 06:11 AM
Hi,

I found the reason why it was throwing object ref... error.
Actually that datasource which was assigned to it has some values null and there was written like CDate(" + ColumnName + ")" so it could not convert a null value to valid datetime value.
0
Svetoslav
Telerik team
answered on 21 Apr 2008, 08:16 AM
Hello Divyesh,

It's good that you have managed to find out the reason for your troubles. I would suggest that you consider using the ISNULL built-in function:

object IsNull(value, defaultValue) 

which returns the defaultValue if the value is null (Nothing in Visual Basic.NET syntax; otherwise returns the value itself).

For a default value you have to consider the most suitable one for your particular case. Since you need to format the TextBox when the current date is greater or equal to a given date, you can use #1-1-1# (January 1st, 0001) which is smaller enough or today's date that you can obtain from the Now() built-in function.

For more information please see Using Expressions.

Sincerely yours,
Svetoslav
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
General Discussions
Asked by
Gourangi
Top achievements
Rank 1
Answers by
Gourangi
Top achievements
Rank 1
Svetoslav
Telerik team
Share this question
or