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

[Solved] Open RadDateTimePicker in cell when it goes in edit mode

3 Answers 152 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Amit Patel
Top achievements
Rank 1
Amit Patel asked on 31 Aug 2010, 04:47 PM
I am looking for a feature that would allow me to open up dateTimePicker in cell when it goes in edit mode. Currently, cell would go in edit mode but the control does not open up until user clicks on a button. I have the IsDropDownOpen set to true, but doesn’t make any effect on control behavior. 

Is there a way to make this open when cell goes in edit mode?

Thanks
Amit

3 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 01 Sep 2010, 02:12 PM
Hi Amit Patel,

You need to set the property of the RadDateTimePicker IsDropDownOpen to "True" once the cell gets into edit-mode, meaning you need to define it in run-time. Defining it into xaml beforehand will not result in any in the DatePicker to be loaded as "open".
 

Regards,
Maya
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
Amit Patel
Top achievements
Rank 1
answered on 01 Sep 2010, 02:41 PM
Maya,
Thanks for the reply. I am already setting the IsDropDownOpen at run time when cell enters into edit mode. Please see CreateCellEditElement method below.

public

 

 

sealed class GridViewDateTimeColumn : GridViewBoundColumnBase

 

{

#region

 

 

Fields/Properties

 

 

 

public static readonly DependencyProperty TimeIntervalProperty =

 

 

 

DependencyProperty.Register(

 

 

 

"TimeInterval",

 

 

 

typeof(TimeSpan),

 

 

 

typeof(GridViewDateTimeColumn),

 

 

 

new System.Windows.PropertyMetadata(TimeSpan.FromHours(1.0)));

 

 

 

public static readonly DependencyProperty InputModeProperty =

 

 

 

DependencyProperty.Register(

 

 

 

"InputMode",

 

 

 

typeof(InputMode),

 

 

 

typeof(GridViewDateTimeColumn),

 

 

 

new System.Windows.PropertyMetadata(InputMode.DateTimePicker));

 

 

 

public TimeSpan TimeInterval

 

{

 

 

get { return (TimeSpan)GetValue(TimeIntervalProperty); }

 

 

 

set { SetValue(TimeIntervalProperty, value); }

 

}

 

 

public InputMode InputMode

 

{

 

 

get { return (InputMode)GetValue(InputModeProperty); }

 

 

 

set

 

{

SetValue(InputModeProperty,

 

value);

 

 

 

switch (value)

 

{

 

 

case InputMode.DatePicker:

 

DataFormatString =

 

"{0:d}";

 

 

 

break;

 

 

 

case InputMode.DateTimePicker:

 

DataFormatString =

 

"{0:g}";

 

 

 

break;

 

 

 

case InputMode.TimePicker:

 

DataFormatString =

 

"{0:t}";

 

 

 

break;

 

}

}

}

#endregion

 

 

Fields/Properties

 

#region

 

 

Methods

 

 

 

public override FrameworkElement CreateCellEditElement(GridViewCell cell, object dataItem)

 

{

 

 

RadDateTimePicker target = new RadDateTimePicker();

 

target.DateTimeWatermarkContent =

 

null;

 

target.InputMode = InputMode;

target.IsDropDownOpen =

 

true;

 

target.IsTooltipEnabled =

 

false;

 

target.TimeInterval = TimeInterval;

target.SetBinding((BindingTarget =

 

RadDateTimePicker.SelectedValueProperty), NewBinding());

 

target.DataContext = cell.DataContext;

target.SelectionChanged -= SelectionChanged;

target.SelectionChanged += SelectionChanged;

 

 

return target;

 

}

 

 

public override object GetNewValueFromEditor(object editor)

 

{

 

 

RadDateTimePicker picker = editor as RadDateTimePicker;

 

 

 

if (picker != null)

 

{

picker.DateTimeText = picker.CurrentDateTimeText;

}

 

 

return base.GetNewValueFromEditor(editor);

 

}

 

 

private Binding NewBinding()

 

{

 

 

Binding binding = new Binding();

 

binding.Mode =

 

BindingMode.TwoWay;

 

binding.NotifyOnValidationError =

 

true;

 

binding.ValidatesOnExceptions =

 

true;

 

binding.UpdateSourceTrigger =

 

UpdateSourceTrigger.Explicit;

 

binding.Path =

 

new PropertyPath(DataMemberBinding.Path.Path);

 

 

 

return binding;

 

}

#endregion

 

 

Methods

 

#region

 

 

Event Handlers

 

 

 

private void SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangedEventArgs e)

 

{

 

 

RadDateTimePicker target = (RadDateTimePicker)sender;

 

 

 

GridViewCell currentCell = target.ParentOfType<GridViewCell>();

 

 

 

if (currentCell != null && currentCell.IsInEditMode)

 

{

currentCell.CommitEdit();

}

}

#endregion

 

 

Event Handlers

 

}

0
Maya
Telerik team
answered on 03 Sep 2010, 03:56 PM
Hi Amit Patel,

You may handle the BeginningEdit event and by invoking a Dispatcher, you may find the RadDateTimePicker and set its IsDropDownOpen Property to "True".
For example:

void playersGrid_BeginningEdit(object sender, GridViewBeginningEditRoutedEventArgs e)
{
    Dispatcher.BeginInvoke(new Action(() =>
    {
        RadDateTimePicker dateEditor = e.Cell.ChildrenOfType<RadDateTimePicker>().FirstOrDefault();
        if(dateEditor != null)
        {
            dateEditor.IsDropDownOpen = true;
        }
    }), null);                 
}
 

Kind regards,
Maya
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
Tags
GridView
Asked by
Amit Patel
Top achievements
Rank 1
Answers by
Maya
Telerik team
Amit Patel
Top achievements
Rank 1
Share this question
or