Completed
Last Updated: 06 Sep 2019 11:42 by ADMIN
Release R3 2019
Enrico
Created on: 05 Feb 2019 08:18
Category: DataForm
Type: Feature Request
0
DataForm: possibility to specify if use DateTimePicker

Good Morning,

It would be nice to have the possibility to choose if use DateTimePicker or DatePicker during the 'AutoGeneratingField' event.

Something like:

if (e.PropertyType.Equals(typeof(DateTime)))
            {
                e.DateTimeMode = ...RadDataForm.DateTimeMode.OnlyDate, //(or .DateTime) 
            }

Because overriding the 'DataFormField' content with a RadDateTimePicker is a little bit intricate especially for the binding/reference losing.

The control is very helpful to make fast user forms prototipe but in this case it lose all its convenience. 

 

Thank you,

Best Regards,

Enrico 

1 comment
ADMIN
Martin Ivanov
Posted on: 06 Feb 2019 08:15
Hi Enrico,

Thank you for sharing your feedback. I am changing the status of this to Approved. I also updated your Telerik points.

Currently, you can achieve this effect by creating a custom DataFormDateField class and override its GetControl() method.
public class CustomDataFormDateField : DataFormDateField
{
    private bool isDateTimePicker = false;
    public bool IsDateTimePicker
    {
        get { return isDateTimePicker = false; }
        set { isDateTimePicker = value; }
    }
 
    protected override Control GetControl()
    {
        if (this.isDateTimePicker)
        {
            RadDateTimePicker control = new RadDateTimePicker();
            if (this.DataMemberBinding != null)
            {
                control.SetBinding(RadDateTimePicker.SelectedValueProperty, this.DataMemberBinding);
            }
 
            control.SetBinding(RadDateTimePicker.IsEnabledProperty, new Binding("IsReadOnly") { Source = this, Converter = new InvertedBooleanConverter() });
            return control;
        }
        else
        {
            return base.GetControl();
        }
    }
}
 
private void RadDataForm_AutoGeneratingField(object sender, Telerik.Windows.Controls.Data.DataForm.AutoGeneratingFieldEventArgs e)
{
    if (e.PropertyType.Equals(typeof(DateTime)))
    {
        e.DataField = new CustomDataFormDateField() { IsDateTimePicker = true };
    }           
}

Regards,
Martin Ivanov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.