Is there a way to make this open when cell goes in edit mode?
Thanks
Amit
3 Answers, 1 is accepted
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".
Maya
the Telerik team
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
}
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