Force DatePicker to be empty after invalid selection

9 posts, 1 answers
  1. Peter Vandenborre
    Peter Vandenborre avatar
    8 posts
    Member since:
    Mar 2010

    Posted 14 Apr 2010 Link to this post

    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
  2. Answer
    Konstantina
    Admin
    Konstantina avatar
    2332 posts

    Posted 19 Apr 2010 Link to this post

    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.
  3. DevCraft banner
  4. Chris Greening
    Chris Greening avatar
    11 posts
    Member since:
    Mar 2010

    Posted 26 Apr 2010 Link to this post

    I also need to be able to do this, Have you been able to do this yet Peter?
  5. Peter Vandenborre
    Peter Vandenborre avatar
    8 posts
    Member since:
    Mar 2010

    Posted 26 Apr 2010 Link to this post

    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
  6. Chris Greening
    Chris Greening avatar
    11 posts
    Member since:
    Mar 2010

    Posted 26 Apr 2010 Link to this post

    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
  7. Peter Vandenborre
    Peter Vandenborre avatar
    8 posts
    Member since:
    Mar 2010

    Posted 26 Apr 2010 Link to this post

    I'm using M-V-VM as well and I can access the control from the code-behind of the View class.
  8. Kaloyan
    Admin
    Kaloyan avatar
    920 posts

    Posted 29 Apr 2010 Link to this post

    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.
  9. Chris Greening
    Chris Greening avatar
    11 posts
    Member since:
    Mar 2010

    Posted 29 Apr 2010 Link to this post

    We implemented the INotifyPropertyChanged method and this is now resolved thanks.
  10. Peter Vandenborre
    Peter Vandenborre avatar
    8 posts
    Member since:
    Mar 2010

    Posted 29 Apr 2010 Link to this post

    I've marked Konstantina's post as answer, thanks for the feedback.
Back to Top
DevCraft banner