Is there a GridViewDateTimeColumn for WPF

6 posts, 1 answers
  1. Dave
    Dave avatar
    31 posts
    Member since:
    Apr 2014

    Posted 15 Aug 2014 Link to this post

    I want to put a GridViewDateTimeColumn into my WPF RadGridView but GridViewDateTimeColumn doesn't seem to exist in Telerik.Windows.Controls (all the other GridView column controls seem to be there, just not this one). Am I missing something?
    Dave
  2. Answer
    Boris
    Admin
    Boris avatar
    276 posts

    Posted 18 Aug 2014 Link to this post

    Hello Dave,

    You are correct - there is no such column as GridViewDateTimeColumn. However, you can create one by following the Create Custom DateTimePicker Column tutorial. In addition, you will need to create a class that derives from GridViewBoundColumnBase and override the CreateCellEditElement() method. For example you can do something like the following:

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

    I attached a sample project that demonstrated the suggested approach. 

    Please examine the attached project and let us know how it goes.

    Regards,
    Boris Penev
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  3. Ravi
    Ravi avatar
    1 posts
    Member since:
    Jul 2012

    Posted 25 Aug 2014 in reply to Boris Link to this post

    Hi Boris,

    I'm using same solution and it works fine except for one thing.

    The DateTimePicker in the editing row doesn't allow the keyboard-input to work seamlessly as compared to the same when you don't place the DateTimePicker as a column.

    When I (1) edit by keyboard and change the date or time part, and (2) press Enter key, it considers the edit.
    But when I (1) edit by keyboard and change the date or time part, and (2) press Tab key, or click outside the DateTimePicker, the editing is lost and I'm back with the old values.

    I don't want the users to always press Enter key to keep their edits from keyboard.

    Please suggest a workaround for this.
  4. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 28 Aug 2014 Link to this post

    Hello,

    I tested the specified steps using the keyboard keys in the demo solution my colleague attached. I was not able to reproduce an issue with committing the edit in case I finish it with the Tab key or clicking on another row/cell. You can check the video I captured to illustrate my test.

    Do you reproduce it in the attached demo project?

    Regards,
    Didie
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
  5. Dave
    Dave avatar
    31 posts
    Member since:
    Apr 2014

    Posted 28 Aug 2014 in reply to Boris Link to this post

    Thanks Boris. I used your sample project to create the control which seems to work fine.
    However I must say I am puzzled that Telerik have not provided this control for WPF. Every GridView Column control that is provided for Windows Forms seems to be provided for WPF except for this one. Is there some reason for this omission?
    Dave
  6. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 28 Aug 2014 Link to this post

    Hi Dave,

    Thank you for sharing your feedback.
    The reason why we have not added such a column is that there was not enough demand. You can always create your custom column to serve the exact scenario you would like.

    Regards,
    Didie
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
Back to Top