When tabbing into an ultraNumericEditor or for that matter any Infragistics control we want all the text to be selected. When we click in a control we want the cursor to be placed where we click. We do not want the control to retain last SelectionStart and SelectionLength values. Basically we are trying to get the Infragistics controls to work like they do In Office 365 Outlook Options.
I have read these posts and a few others.
Different behavior of text selection when tabbing into an ultratexteditor
Numeric Editor Question
I can accomplish this in the ultraTextEditor by using the Enter event but does not work if I use the AfterEnterEditMode. I thought this would also solve my issues with ultraNumericEditor, ultraCurrencyEditor and ultraDateTimeEditor because they seem to be built using some variation of textbox/ultraTextEditor. However the event does not work the same. It always selects all the text.
I found a way to get the desired behaviour in ultraNumericEditor, ultraCurrencyEditor and ultraDateTimeEditor by setting SelectionStart and SelectionLength to basically select all characters during the Validating event. I could do this in the Leave event if that is better. It would have been much easier if I could simply keep the control from retaining this information but I could not find a way.
I have attached a test solution with the controls working as I would like them to. Could be luck that they are working correctly.
The questions I have:
0081.SelectAll.zip
Hello Michael,
I have been investigating into the behavior you are seeing, and I have some information for you on this matter. I will answer the questions in the order they were asked.
1. I think these changes are solid, but they may not be working in the way you expect. The Validating event is firing when you leave the editor, and so when you tab back into the editor, this is likely because it is retaining the selection from the last time you exited. The mouse click is resetting the cursor position, as expected.
2. The UltraTextEditor is different than the other controls, since it is not a “masked” editor. When in edit mode, the UltraTextEditor uses a .NET TextBox, whereas the other “masked” editors are using a custom element.
3. I believe this is due to the same reason as point 2. This behavior can be implemented using the KeyDown event of other editors, though. I will be checking with our development teams to see if the masked editors are supposed to support Ctrl+A and Alt+Backspace, though.
Please let me know if you have any other questions or concerns on this matter.
Thank you for the response. Not sure what you mean when you say may not be working in the way expect. By default the control retains SelectionStart and SelectionLength. If the control is going to save this information off the only choice I had was to set SelectionStart and SelectionLength to specific values to ensure it retained the correct information to select all when they exited the control. I would rather not have to do this at all but due to the design of the control it is the only way I have been able to get the desired result. I really just wanted to clear SelectionStart and SelectionLength when they exited so it would act like it did the first time the user tabbed into the control. I could not find a way to do this. I am open to suggestion or a better way.
Thank you for your update on this matter.
From your response, it sounds like it is working in the way that you would expect. As mentioned in my above response, clicking into the editors will clear the selection and place the caret where you clicked, and tabbing in will revert to the “saved selection” which you are setting in your Validating event in this case. I think this is a valid way of ensuring that you select all when tabbing back into the editors while also ensuring that the caret is placed where you click.
An alternative event that you could potentially set this in would be the Before/AfterExitEditMode events as well. Unfortunately, the Before/AfterEnterEditMode events do not have any information on whether or not it is coming from a click or tab navigation, so I can’t really recommend doing this there.
I actually do not trap on tab or any other keystrokes. I let the control take care of that I only trick the control when exiting by setting SelectionStart and SelectionLength. Using the BeforeExitEditMode actually works really well. It also allows me to use only one event instead of two. I can also remove the fields that are no longer needed. From what I can tell I am accomplishing the same goal just with less overhead. I have attached the updated solution.0456.SelectAll2.zip
Thank you for your update on this matter. I am glad that BeforeExitEditMode is working better for you in this case and is allowing you to achieve your goal with less overhead.
It appears that the UltraMaskedEdit control’s architecture is quite a bit different than the other “masked editors.” It actually has a completely different base-class and as such, a different API.
I was going to mention that UltraMaskedEdit works just like UltraTextEditor. I only needed to call SelectAll() in the control Enter event to accomplish my goal. I found that strange considering the other controls were built as "masked" editors. I also found it strange that UltraMaskedEdit does not have BeforeExitEditMode or AfterEnterEditMode.