11-03-2015 12:19 PM
For convenience, I'd like the behavior of my numeric controls to auto select the entire value when I click the control. So when it gets focus, the value should be selected.
I'm not seeing a way of doing this. Any ideas? The increment buttons on a numeric will select it, but these datatypes I have set to float. So incrementing doesn't make much sense. In my case, I have the user punching in values with the keyboard. It would be nice to not have to first select the 0.000 already present before data entry.
Thoughts?
Solved! Go to Solution.
11-03-2015 03:53 PM
I don't think you can do that with numerics, but you can with text with the ATTR_TEXT_SELECTION_START/LENGTH attributes. Simply set it when you get a FOCUS event.
11-03-2015 04:37 PM
Yeah, that's what I was thinking. Oh well.
11-04-2015 02:33 AM
Just as a side note, if the user tabs among controls present value will be automatically selected. The same happens on a single control if he clicks on the control label instead of inside the input area.
Having said that, with several years of experience I know users are not willing to learn this simple trick and will always click inside the control complaining they must additionally double-click to select the value...
11-04-2015 03:02 AM
Maybe you could try and generate a shift-tab followed by a tab to emulate it when the user clicks on it (left clic event or got focus event). Use FakeKeyStroke() for that.
11-04-2015 03:37 AM
Unfortunately not: it seems there remains some click event in the queue that makes the selection disappear. If you process draw events between the two FakeKeystroke you see the text selected and then unselected.
11-04-2015 03:59 AM - edited 11-04-2015 04:00 AM
@gdargaud: with a little modification your idea can work!
You simply need to simulate a Home + Shift-End event to select text:
if (event == EVENT_GOT_FOCUS) { FakeKeystroke (VAL_HOME_VKEY); FakeKeystroke (VAL_SHIFT_MODIFIER | VAL_END_VKEY); }
This is valid for both text and numeric controls.
11-04-2015 08:15 AM
I love this user group! Nice solution, guys. Works very nicely.
11-04-2015 08:40 AM
Yeah, well, don't forget to test it also for the keyboard users, as it's usually a bad idea to try and second-guess the users... :womanmad: