Editing hours in a DateTime column

25 posts, 1 answers
  1. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 12 Jun 2010 Link to this post

    How do I let the user edit the hour in a DateTime column.
    When I click to edit, just the Date is editable, the hour vanishes

    Thank you
  2. Answer
    Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 14 Jun 2010 Link to this post

    Hello,

    You can check this demo for more info.

    Sincerely yours,
    Vlad
    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. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 14 Jun 2010 Link to this post

    Hi,

    This is a great demo.  Thank you to show me exactly what I need.
    Now I just don't know how to implement all this in my actual project which have all the columns added dinamycilly by C# code

    When I look at your demo I see a bunch of source code,  I'm wondering how I have to start and what I really need in all this to have the same column addec by C# code.
  5. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 14 Jun 2010 Link to this post

    Hello,

     You need DateTimePickerColumn - will work no matter if you have this declared in XAML or added by code.

    Sincerely yours,
    Vlad
    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.
  6. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 14 Jun 2010 Link to this post

    I'm trying

    So I just picked up your DateTimePickerColumn class but it is not recognizing the DateTimePicker in it
    Where it is ?

    However I added the same using namespaces as yours
  7. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 14 Jun 2010 Link to this post

    I see that you have the DateTimePickler as a UserControl so I need this in my project else your DateTimePickerColumn wont work.
    And if I need it just a CopyPaste will not make it very easy to me I mean namespaces and all this.
  8. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 14 Jun 2010 Link to this post

    Hello,

     You can find the DatePicker in the separate class in the same example however if you want you can do the same simply by creating needed controls (RadDatePicker and RadTimePicker) in CreateCellEditElement dynamically.

    Kind regards,
    Vlad
    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. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 14 Jun 2010 Link to this post

    Ok Now I have the Class in place, how do I implement it in this method so I can have the column I need :

     public static void TelerikAddDateTimePickerColumn(RadGridView GridView, string FrenchCaption, string EnglishCaption, string BindingPath, bool IsVisible, bool IsReadOnly, double Width, Telerik.Windows.Controls.SortingState SortingState, bool IsGroupped)  
     {  
         Telerik.Windows.Controls.GridViewDataColumn gvdc = new Telerik.Windows.Controls.GridViewDataColumn();  
     
         if (FrenchCaption != "")  
             gvdc.Header = FrenchCaption;  
         else 
             gvdc.Header = EnglishCaption;  
     
         gvdc.IsVisible = IsVisible;  
         gvdc.IsReadOnly = IsReadOnly;  
     
         if (Width != -1)  
             gvdc.Width = Width;  
     
         gvdc.SortingState = SortingState;  
     
         gvdc.DataMemberBinding = new System.Windows.Data.Binding(BindingPath);  
     
         GridView.Columns.Add(gvdc);  
     }  
     

    I would also need a way to make the Date part readonly and not editable but just the hour.
  10. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 14 Jun 2010 Link to this post

    Hi,

     You need to create the custom column and add it the grid just like any other column. You can also set IsReadOnly for desired control in your custom column.

    All the best,
    Vlad
    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.
  11. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 14 Jun 2010 Link to this post

    Seems good.  I'm going to tests all this and get back to you.
  12. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 14 Jun 2010 Link to this post

    As soon as I click on the cell here's what I get :

    [DP_PropertyTypeCannotBeSetOnObject]  
    Arguments:   
    Debugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem. See http://go.microsoft.com/fwlink/?linkid=106663&Version=4.0.50524.0&File=System.Windows.dll&Key=DP_PropertyTypeCannotBeSetOnObject 
     
       at System.Windows.DependencyObject.ValidateDependencyPropertyParameter(DependencyProperty dp)  
       at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet)  
       at System.Windows.Data.BindingOperations.SetBinding(DependencyObject target, DependencyProperty dp, BindingBase binding)  
       at GearObjects.SCClasses.DateTimePickerColumn.CreateCellEditElement(GridViewCell cell, Object dataItem)  
       at Telerik.Windows.Controls.GridView.GridViewCell.SetEditorContent()  
       at Telerik.Windows.Controls.GridView.GridViewCell.ShowEditor()  
       at Telerik.Windows.Controls.GridView.GridViewCell.ToggleEditor()  
       at Telerik.Windows.Controls.GridView.EditContext.OnCellEditModeChanged(GridViewCell cell, Boolean newIsInEditMode)  
       at Telerik.Windows.Controls.GridView.GridViewCell.IsInEditModeChanged(DependencyObject target, DependencyPropertyChangedEventArgs e)  
       at Telerik.Windows.PropertyMetadata.<>c__DisplayClass1.<Create>b__0(DependencyObject d, DependencyPropertyChangedEventArgs e)  
       at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object oldValue, Object newValue)  
       at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)  
       at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet)  
       at Telerik.Windows.Controls.GridView.EditContext.SwitchCellToEditMode(GridViewCell cell)  
       at Telerik.Windows.Controls.GridView.EditContext.BeginEdit(GridViewCell gridViewCell)  
       at Telerik.Windows.Controls.GridView.EditContext.OnCellMouseDown(GridViewCell cell)  
       at Telerik.Windows.Controls.GridView.GridViewCell.OnMouseLeftButtonDown(MouseButtonEventArgs e)  
       at System.Windows.Controls.Control.OnMouseLeftButtonDown(Control ctrl, EventArgs e)  
       at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)  
     
  13. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 14 Jun 2010 Link to this post

    Hi,

     You get this on our online demo?

    Regards,
    Vlad
    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.
  14. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 14 Jun 2010 Link to this post

    Of course not but by trying to implement your code in mine I certainly ends up with come kind of incompatibility somewhere.

    Here's the code I have copied and mofied as you said :

    public class DateTimePickerColumn : GridViewBoundColumnBase  
    {  
        public override FrameworkElement CreateCellEditElement(GridViewCell cell, object dataItem)  
        {  
            this.BindingTarget = RadTimePicker.SelectedTimeProperty;  
     
            RadTimePicker picker = new RadTimePicker();  
            picker.SetBinding(this.BindingTarget, this.CreateValueBinding());  
     
            return picker;  
        }  
     
        private Binding CreateValueBinding()  
        {  
            Binding valueBinding = new Binding();  
            valueBinding.Mode = BindingMode.TwoWay;  
            valueBinding.NotifyOnValidationError = true;  
            valueBinding.ValidatesOnExceptions = true;  
            valueBinding.UpdateSourceTrigger = UpdateSourceTrigger.Explicit;  
            valueBinding.Path = new PropertyPath(this.DataMemberBinding.Path.Path);  
     
            return valueBinding;  
        }  
    }  
     

    And here's the method that uses it to add the column I need to my grid :

     public static void TelerikAddDateTimePickerColumn(RadGridView GridView, string FrenchCaption, string EnglishCaption, string BindingPath, bool IsVisible, bool IsReadOnly, double Width, Telerik.Windows.Controls.SortingState SortingState, bool IsGroupped)  
     {  
         DateTimePickerColumn dtpc = new DateTimePickerColumn();  
           
         if (FrenchCaption != "")  
             dtpc.Header = FrenchCaption;  
         else 
             dtpc.Header = EnglishCaption;  
     
         dtpc.IsVisible = IsVisible;  
         dtpc.IsReadOnly = IsReadOnly;  
     
         if (Width != -1)  
             dtpc.Width = Width;  
     
         dtpc.SortingState = SortingState;  
     
         dtpc.DataMemberBinding = new System.Windows.Data.Binding(BindingPath);  
     
         GridView.Columns.Add(dtpc);  
     }  
     
  15. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 14 Jun 2010 Link to this post

    Ok I saw the error but after fixed it for RadTimePicker.SelectedTimeProperty, when I edit the cell, the hour that was there is not present when editing.  The cell is blank

    I edited my message with the 2 code and everything works except when I edit the cell, the cell is blank and doesn't show me the hour I see when not in edit mode
  16. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 14 Jun 2010 Link to this post

    I'm facing other weird things like if I enter a time even tought I see nothing, after hiting TAB, it says "Input not in correct format"
    Also if I hit TAB again my origianl cell content vanishes
  17. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 14 Jun 2010 Link to this post

    I finally succeeded by implementing the whole thing. 
    There's only a last thing not working.  When I hit TAB instead of ENTER when I'm finished editing, it doesn't update the value

    When hiting ENTER it does keep the new value but not TAB
  18. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 14 Jun 2010 Link to this post

    Oh and by the way could you jsut tell me where I put code so I can make the Date Part readonly
    And letting the user just access to the time part AFTER the column have been created !
  19. Nedyalko Nikolov
    Admin
    Nedyalko Nikolov avatar
    871 posts

    Posted 17 Jun 2010 Link to this post

    Hi Marc Roussel,

    Unfortunately with the current version of RadControls this issue cannot be solved. I've just talked with the team responsible for RadDateTimePicker control and they ensured me that with Q2 release this issue will be fixed.
    Sorry for the inconvenience caused.

    Kind regards,
    Nedyalko Nikolov
    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
  20. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 17 Jun 2010 Link to this post

    Thank you sure.  For now I've been able to do a workaround which just consist of having the control exposed so I can set the IsReadyOnly
  21. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 26 Jul 2010 Link to this post

    I'm with version 714 and either ENTER or TAB there's nothing changed on the cell.  I debug in RowEditEnded and I see the old value not the new one.  Could you help me on this ?
  22. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 26 Jul 2010 Link to this post

    In this class of yours,  I did debug deeply and I get into the HandleSelectionChanged and it is triggered as soon as I edit the cell but not after I edited it and then I always end up with the old value either in CellEditEnded or RowEditEnded.  I'm lost

    public partial class DateTimePicker
    {
        #region ' Dependency Properties 
            public static readonly DependencyProperty SelectedDateProperty =
                DependencyProperty.Register("SelectedDate", typeof(DateTime?), typeof(DateTimePicker),
                                        new PropertyMetadata(null, new PropertyChangedCallback(OnSelectedDateChanged)));
            #endregion
      
        #region ' Properties '
            public DateTime? SelectedDate
            {
                get
                {
                    return (DateTime?)this.GetValue(SelectedDateProperty);
                }
                set
                {
                    this.SetValue(SelectedDateProperty, value);
                }
            }
            public RadDatePicker CalenderPart
            {
                get { return Calender; }
            }
            public RadTimePicker TimePart
            {
                get { return TimePicker; }
            }
            #endregion
      
        #region ' Constructor '
            public DateTimePicker()
            {
                this.InitializeComponent();
            }
            #endregion
      
        #region ' Events '
            private static void OnSelectedDateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
            {
                DateTimePicker picker = (DateTimePicker)d;
                picker.OnSelectedDateChanged((DateTime?)e.NewValue);
            }
            private void OnCalenderSelectionChanged(object sender, SelectionChangedEventArgs e)
            {
                this.HandlePickersSelectionChanged();
            }
            private void OnSelectedDateChanged(DateTime? selectedDate)
            {
                this.TimePicker.SelectedTime = selectedDate != null ? selectedDate.Value.TimeOfDay : (TimeSpan?)null;
                this.Calender.SelectedDate = selectedDate;
            }
            private void OnTimeChanged(object sender, EventArgs e)
            {
                this.HandlePickersSelectionChanged();
            }
            #endregion
      
        #region ' Methods '
        private void HandlePickersSelectionChanged()
        {
            this.SelectedDate = this.Calender.SelectedDate + this.TimePicker.SelectedTime;
        }
        #endregion
    }
  23. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 26 Jul 2010 Link to this post

    Sadly the application is in production and they're waiting for me to fix this very now !
  24. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 26 Jul 2010 Link to this post

    private void OnTimeChanged(object sender, EventArgs e)
    {
        this.HandlePickersSelectionChanged();
    }

    For your information
    This isn't triggered if I change the time

    It is well wired in xaml and it was working in version 603
    as I remember well
  25. Stefan Dobrev
    Admin
    Stefan Dobrev avatar
    790 posts

    Posted 30 Jul 2010 Link to this post

    Hi Marc,

    Could you please take a look at this updated online example which illustrates a custom column using the DateTimePicker control? The tricky part is the GetNewValueFromEditor where the magic happens.

    Best wishes,
    Stefan Dobrev
    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
  26. Marc Roussel
    Marc Roussel avatar
    429 posts
    Member since:
    Dec 2009

    Posted 30 Jul 2010 Link to this post

    It's all good.  Thank you very much
Back to Top
DevCraft banner