user changes date

5 posts, 0 answers
  1. Sason
    Sason avatar
    32 posts
    Member since:
    Aug 2012

    Posted 20 Sep 2010 Link to this post

    Hi,

    In the DateTimePicker I'm looking for an event which happens when a user changes the date (by mouse or keyboard) but not when a date is set- (for example:  DateTimePicker1.Value=DateTime.Now)

    In other controls I found events or properties which supported this scenario, but in this case I couldn't find.

     

    Thanks

  2. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 21 Sep 2010 Link to this post

    Hello Dror,

    I don't know exactly what you are trying to achieve, but there shouldn't be an event like the one you described because then you would have inconsistencies in the data displayed and the actual data value of the control.

    For example let's say you have the value of the control bounded, and you have a form with a datetimepicker and a button that set's the date of the datetimepicker to today or some date (although i know this a bad example because the today button should be used as part of the footer on the calendar) when the user changes the date by some input, the ValueChanged event fires, but if after that, the user changes his mind and clicks the button, the date will change programmatically and the event won't fire, so it will create inconsistencies between what the user sees and what is the actual bounded value.

    If you just don't want some logic to be performed while a date is being changed programmatically you could try using some flags in order to check if this was a programmatic change or not, the simplest one i could think of now would be a boolean flag set before changing the value, and resetting it either inside the value changed event of after setting the value.

    If there is something else i can do to help, please let me know,

    Best Regards,
    Emanuel Varga

  3. UI for WinForms is Visual Studio 2017 Ready
  4. Sason
    Sason avatar
    32 posts
    Member since:
    Aug 2012

    Posted 21 Sep 2010 Link to this post

    Hi,

    Let me explain myself again:

     

    There is a certain check that must be done when a user changes a date (by mouse or by a keyboard) I don't want this check to happen when date is change programmatically.

    The event that fires when the date is change is the ValueChanged.

    The problem is that  this event fires in both cases (date changes by user/  programmatically).

     

    One solution is to use a flag, in order to check if this was a programmatic change or not,  and set it before changing the value programmatically,  then in the  ValueChanged event check the flag.

    This solution is not realistic since I use this functionality in few forms.

     

    Any othe idea?

     

    Thanks.

  5. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 21 Sep 2010 Link to this post

    Hello again,

    If you need a custom behavior for this you could try extending the control add the necessary functionality there and use that control everywhere you need. In that control there are server options available, the one with the flag being the easiest to achieve, or you can use another property for programmatically changing the data and do all the necessary connections there.

    Please let me know if you need more help in this, or if you have any other questions,

    Best regards,
    Emanuel Varga
  6. Dobry Zranchev
    Admin
    Dobry Zranchev avatar
    348 posts

    Posted 23 Sep 2010 Link to this post

    Hi,

    Thank you for writing us.

    You could create a custom control that inherits the RadDateTimePicker control. In this control you could create your own property that behaves as a value setter. In this setter you could raise a flag that the value is changed from the custom setter. Also, you should override the OnValueChanged method and call the event only if the value is not changed from the custom setter.
    class CustomDateTimePicker: RadDateTimePicker
    {
        private bool isCustomSet = false;
     
        protected override void OnValueChanged(EventArgs e)
        {
            if (!this.isCustomSet)
            {
                base.OnValueChanged(e);
            }
     
            this.isCustomSet = false;
        }
     
        public void CustomSetter( DateTime value )
        {
            this.isCustomSet = true;
            this.Value = value;
        }
    }

    I hope that this will help you. If you have other questions, feel free to contact us.

    Kind regards,
    Dobry Zranchev
    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
Back to Top
UI for WinForms is Visual Studio 2017 Ready