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

Editing hours in a DateTime column

24 Answers 211 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Marc Roussel
Top achievements
Rank 2
Marc Roussel asked on 12 Jun 2010, 12:45 PM
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

24 Answers, 1 is accepted

Sort by
0
Accepted
Vlad
Telerik team
answered on 14 Jun 2010, 07:24 AM
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.
0
Marc Roussel
Top achievements
Rank 2
answered on 14 Jun 2010, 01:38 PM
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.
0
Vlad
Telerik team
answered on 14 Jun 2010, 01:44 PM
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.
0
Marc Roussel
Top achievements
Rank 2
answered on 14 Jun 2010, 01:59 PM
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
0
Marc Roussel
Top achievements
Rank 2
answered on 14 Jun 2010, 02:03 PM
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.
0
Vlad
Telerik team
answered on 14 Jun 2010, 02:05 PM
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.
0
Marc Roussel
Top achievements
Rank 2
answered on 14 Jun 2010, 02:15 PM
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.
0
Vlad
Telerik team
answered on 14 Jun 2010, 02:21 PM
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.
0
Marc Roussel
Top achievements
Rank 2
answered on 14 Jun 2010, 02:26 PM
Seems good.  I'm going to tests all this and get back to you.
0
Marc Roussel
Top achievements
Rank 2
answered on 14 Jun 2010, 02:55 PM
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)  
 
0
Vlad
Telerik team
answered on 14 Jun 2010, 02:56 PM
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.
0
Marc Roussel
Top achievements
Rank 2
answered on 14 Jun 2010, 02:59 PM
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);  
 }  
 
0
Marc Roussel
Top achievements
Rank 2
answered on 14 Jun 2010, 03:06 PM
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
0
Marc Roussel
Top achievements
Rank 2
answered on 14 Jun 2010, 03:14 PM
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
0
Marc Roussel
Top achievements
Rank 2
answered on 14 Jun 2010, 04:27 PM
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
0
Marc Roussel
Top achievements
Rank 2
answered on 14 Jun 2010, 05:05 PM
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 !
0
Nedyalko Nikolov
Telerik team
answered on 17 Jun 2010, 12:05 PM
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
0
Marc Roussel
Top achievements
Rank 2
answered on 17 Jun 2010, 12:19 PM
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
0
Marc Roussel
Top achievements
Rank 2
answered on 26 Jul 2010, 06:56 PM
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 ?
0
Marc Roussel
Top achievements
Rank 2
answered on 26 Jul 2010, 07:09 PM
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
}
0
Marc Roussel
Top achievements
Rank 2
answered on 26 Jul 2010, 07:10 PM
Sadly the application is in production and they're waiting for me to fix this very now !
0
Marc Roussel
Top achievements
Rank 2
answered on 26 Jul 2010, 07:15 PM
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
0
Stefan Dobrev
Telerik team
answered on 30 Jul 2010, 09:15 AM
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
0
Marc Roussel
Top achievements
Rank 2
answered on 30 Jul 2010, 10:52 AM
It's all good.  Thank you very much
Tags
GridView
Asked by
Marc Roussel
Top achievements
Rank 2
Answers by
Vlad
Telerik team
Marc Roussel
Top achievements
Rank 2
Nedyalko Nikolov
Telerik team
Stefan Dobrev
Telerik team
Share this question
or