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

Report Parameters DateTime Picker

7 Answers 839 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Rob Harris
Top achievements
Rank 1
Rob Harris asked on 01 Jul 2010, 02:57 PM
I have a Windows Forms Telerik report that uses a parameter of type DateTime. When I display the report in the WinForms ReportViewer control the parameter is displayed at the top of the report with the user able to select a date, however the control does not allow them to select a time. How can I get the ReportViewer's Datetime picker to display the date and time?

I'm using version 3.2.9.1211 of Telerik.Reporting dll.

7 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 02 Jul 2010, 03:50 PM
Hi Rob Harris,

The DateTime Report Parameters UI by default only allows Date picking. Our suggestion in your case would be to create a custom UI for the parameters instead of using the default one. Just set the Report Parameters Visibility to False and add Windows Forms controls that will feed the Report Parameters in code behind, as shown in the following code snippet:

private void button1_Click(object sender, EventArgs e)
{
    var report1 = new ClassLibrary1.TestReport();
    report1.ReportParameters["Parameter1"].Value = dateTimePicker1.Value;
    reportViewer1.Report = report1;
    reportViewer1.RefreshReport();
}

All the best,
Peter
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
Matt
Top achievements
Rank 1
answered on 28 Feb 2012, 02:50 PM
I can't seem to get this to work where do you place it?  I am trying ot evalute if this product will work for us and we will need a datetime paramater for almost every report and we need to be able to pick time and date.  when i put in report.cs file the  designer blows up.

matthew.majerus@xeta.com
0
Rob Harris
Top achievements
Rank 1
answered on 28 Feb 2012, 04:35 PM
You need to add a DateTime picker to the form which launches the report, rather than the report itself. So for example, I have a report called Report1 which has a DateTime parameter. In my launching form (Form1) I create an instance of Report1, assign the selected DateTime to the appropriate parameter (the DateTime value comes from a DateTimePicker also on Form1), and then, in this case, display the report in the Telerik Report Viewer, again on the same form (we could directly print the report at this point too) .

 

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            var report = new Report1();
            report.ReportParameters["MyDateParameter"].Value = dateTimePicker1.Value;
            reportViewer1.Report = report;
            reportViewer1.RefreshReport();
 
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            this.reportViewer1.RefreshReport();
        }
    }

 

 

0
Alex
Top achievements
Rank 1
answered on 06 Mar 2014, 05:31 PM
This is a pretty crappy solution. Only allow date to be selected for DateTIME parameters? Makes zero sense.
0
KS
Top achievements
Rank 1
answered on 06 Mar 2014, 08:31 PM
Hi,

Go for the HTML5 viewer, just switching kendoDatepicket to kendoDateTimepicker and all is working :)

-KS
0
ajpetersen
Top achievements
Rank 1
answered on 07 Mar 2014, 06:53 PM
I am doing something similar in WPF using MVVM. My issue was when a user selected a date, I needed to filter the results into a begin date and end date, starting at 2:00 pm. I was able to accomplish this by using the WPF datepicker and the code below. My question is how would I achieve this same functionality following the MVVM best practices? I am not sure how I would set and refresh the report source from my view model.

private void DatePicker_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
        {
            DateTime? date = ReportDatePicker.SelectedDate;

            if (rvMain != null && date.HasValue)
            {
                DateTime beginDate = date.Value.AddHours(-10); //setting range from 2pm to 2pm
                DateTime endDate = date.Value.AddHours(14);

                var report = new DealerDetails();

                report.ReportParameters["BeginDate"].Value = beginDate;
                report.ReportParameters["EndDate"].Value = endDate;

                rvMain.ReportSource = report;
                rvMain.RefreshReport();
            }
        }








0
Peter
Telerik team
answered on 12 Mar 2014, 05:13 PM
Hi Andrew,

Generally you can keep the default report parameter and only modify the report parameter value with expression in the report definition directly. For example:

=Date(2014,12,30).AddHours(CDbl(14))
or
= CDate(Parameters.Parameter1.Value).AddHours(CDbl(14))

Still if you prefer to utilize your own parameters UI with MVVM in mind our suggestion is to use Data Binding for the Datepicker.Value and ReportViewer.ReportSource. Then from your ViewModel property that is binded to the Datepicker.Value you have to trigger property changed for the property that is binded to the ReportViewer.ReportSource with an updated ReportSource.Parameters.


Regards,
Peter
Telerik
 

DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

 
Tags
General Discussions
Asked by
Rob Harris
Top achievements
Rank 1
Answers by
Peter
Telerik team
Matt
Top achievements
Rank 1
Rob Harris
Top achievements
Rank 1
Alex
Top achievements
Rank 1
KS
Top achievements
Rank 1
ajpetersen
Top achievements
Rank 1
Share this question
or