Hello,
I have a grid that contains a DateTime column. I only care about the time portion so the mask input is hh:mm:ss.
By default when the grid enters edit mode (either by clicking or tabing into the cell) the whole text is selected. I would like it to select the number section the user clicked (hour, minutes or seconds). This post already provides a solution for the stand alone UltraDateTime editor (thanks Mike!).
Following the same logic, I inherited a grid from the UltraGrid and added this:
protected override void OnAfterEnterEditMode()
{
base.OnAfterEnterEditMode();
SelectNumberSection();
}
protected override void OnMouseDown(MouseEventArgs e)
base.OnMouseDown(e);
private void SelectNumberSection()
if (this.ActiveCell != null
&& this.ActiveCell.IsInEditMode)
if (this.ActiveCell.EditorResolved is DateTimeEditor)
((DateTimeEditor)this.ActiveCell.EditorResolved).PerformAction(Infragistics.Win.UltraWinMaskedEdit.MaskedEditAction.SelectSection, false, false);
Basically it tries to select the current number section if the editor is a DateTimeEditor, but it's not working. When I click the cell the whole text is selected (that's the default behavior). Only if I click a second time the number section is selected.
I guess somehow the grid selects the whole text after OnAfterEnterEditMode is called.
Maybe there is a better place to call my logic?
Thanks.
You might be able to get around that by calling your 'SelectNumberSection' method asynchronously, i.e., use the BeginInvoke method to post the call so that it happens after all the OnMouseDown logic has been processed.
I chenged the implementation to be like this:
BeginInvoke(new MethodInvoker(
() =>
((DateTimeEditor)this.ActiveCell.EditorResolved).PerformAction(Infragistics.Win.UltraWinMaskedEdit.MaskedEditAction.SelectSection, false, false))
);
But still doesn't work.