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.
Thanks for the answer Mike.
Actually both my code and your code will do the work. The problem was I had my grid set to DisplayLayout.Override.CellClickAction = EditAndSelect.
I started with a brand new grid and both solutions work as expected.
I tried this out without the BeginInvoke and only using the AfterEnterEditMode event (without deriving from the grid) and it seems to work fine for me.All I did was this:
private void ultraGrid1_AfterEnterEditMode(object sender, EventArgs e) { this.SelectNumberSection(); } private void SelectNumberSection() { UltraGridCell cell = this.ultraGrid1.ActiveCell; if (cell != null && cell.IsInEditMode) { if (cell.EditorResolved is DateTimeEditor) { ((DateTimeEditor)cell.EditorResolved).PerformAction(Infragistics.Win.UltraWinMaskedEdit.MaskedEditAction.SelectSection, false, false); } } }
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.
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.