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

Force DatePicker to be empty after invalid selection

8 Answers 62 Views
DatePicker
This is a migrated thread and some comments may be shown as answers.
Peter Vandenborre
Top achievements
Rank 1
Peter Vandenborre asked on 14 Apr 2010, 03:05 PM
Hello,

I twoway bind a datepicker to a DateTime. I want to check if this date is before an end date, if not, I want the DatePicker to be empty again. In the setter of the property I make the evaluation and if the selection was invalid I put the DateTime property to null.

However the DatePicker fills in the selected (invalid) date anyway!! How can I force it to be empty in this case?

        public DateTime? EmployeeDateFrom  
        {  
            get { return _employeeDateFrom; }  
            set 
            {  
                if (_employeeDateFrom == value)  
                    return;  
 
                if(value > EmployeeDateTo)  
                {  
                    ShowDateFilterErrorDialog("Invalid date selection");  
                    _employeeDateFrom = null;  
                    return;  
                }  
 
                _employeeDateFrom = value;  
                FilterEmployeeList(EmployeeDateFrom, EmployeeDateTo);  
            }  
        } 

Many thanks in advance!

Peter

8 Answers, 1 is accepted

Sort by
0
Accepted
Konstantina
Telerik team
answered on 19 Apr 2010, 03:15 PM
Hello Peter,

Thank you for contacting us.

I can suggest implementing PropertyChanged event of the INotifyPropertyChanged interface. You will need this to update the value of the DatePicker.

Please let us know if that helped you and if you have any further questions.

Greetings,
Konstantina
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
Chris Greening
Top achievements
Rank 1
answered on 26 Apr 2010, 04:47 PM
I also need to be able to do this, Have you been able to do this yet Peter?
0
Peter Vandenborre
Top achievements
Rank 1
answered on 26 Apr 2010, 04:57 PM
Hi,

I've solved it in another way because of time pressure. I've created a public method in the view.
I've got a two way binding between the date picker and a property, and I've put the code below in the setter of that property.

 

 

 

 

                if(value > EmployeeDateTo)  
                {  
                    ShowWarningMessageDialog("","Not allowed");  
                    View.SetEmployeeDateFromFilter(null);  
                    _employeeDateFrom = null;  
                    return;  
                } 


As you can see I've created a public method in my View class (code below):

        public void SetEmployeeDateFromFilter(DateTime? dateTime)  
        {  
            dpFromDate.SelectedDate = dateTime;  
        } 

This way the datepicker is empty again in the view as well. Hope this helps you out, I haven't come around yet to try the solution that Konstantina proposed.

Greets,

Peter
0
Chris Greening
Top achievements
Rank 1
answered on 26 Apr 2010, 05:00 PM
Thanks Peter,

I'll give it a go but I'm using M-V-VM so not sure if I can access the control from the .cs file
0
Peter Vandenborre
Top achievements
Rank 1
answered on 26 Apr 2010, 05:06 PM
I'm using M-V-VM as well and I can access the control from the code-behind of the View class.
0
Kaloyan
Telerik team
answered on 29 Apr 2010, 09:22 AM
Hello Peter Vandenborre,

This is a possible solution. The INotifyPropertyChanged pattern is also acceptable.

All the best,
Kaloyan
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
Chris Greening
Top achievements
Rank 1
answered on 29 Apr 2010, 09:29 AM
We implemented the INotifyPropertyChanged method and this is now resolved thanks.
0
Peter Vandenborre
Top achievements
Rank 1
answered on 29 Apr 2010, 09:45 AM
I've marked Konstantina's post as answer, thanks for the feedback.
Tags
DatePicker
Asked by
Peter Vandenborre
Top achievements
Rank 1
Answers by
Konstantina
Telerik team
Chris Greening
Top achievements
Rank 1
Peter Vandenborre
Top achievements
Rank 1
Kaloyan
Telerik team
Share this question
or