Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1960
In a DateTime column select the minutes text when entering edit mode
posted

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);

SelectNumberSection();

}

 

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.

Parents Reply Children