03-07-2023 07:48 AM
I tried to catch the keystroke in key Down event with no effect. Its properly because the value are put in after the keydown event.......
Is there any other way to solve to problem?
Solved! Go to Solution.
03-07-2023 08:26 AM
Can you attach the code so that we can reproduce your issue and understand your question better?
03-07-2023 08:30 AM
03-07-2023 09:17 AM
Hi both of you. Thank you for your reply.
I tried to follow your advice gerdW but apparently in the wrong way. It's possible to put in letters as well.
I uploaded my code
03-07-2023 09:38 AM
Gerd meant like this.
The concept you are looking for is called "filter event". Those are the ones with a question mark at the end. They allow you to prevent further processing by wiring true to the "discard" terminal.
You will have to refine it a little because you can still input characters with the apostrophe modifier.
03-07-2023 11:43 AM - edited 03-07-2023 11:51 AM
If you really only want to allow 0..9, here's what you could do.
Most likely you also want to allow the period and e.g. editing keys such as <backspace> and <del>, etc.)
I don't understand why you would write the ItemNames property to itself. In general, listboxes are not a great way for user data input. Can you explain the purpose of all this? I am sure there is a much better way. For example, you could sense a double-click event and launch a dialog containing the current items for that value (i.e. row), allowing you to enter/OK new values in the allowed fields using numeric controls or cancel the dialog.
03-07-2023 12:17 PM - edited 03-08-2023 09:00 AM
@altenbach wrote:
For example, you could sense a double-click event and launch a dialog containing the current items for that value (i.e. row), allowing you to enter/OK new values in the allowed fields using numeric controls or cancel the dialog.
Here's a very simple draft for that.
(note that you should either disable allowing to close the popup or handle the panel close event to return the input unchanged. You should also no longer allow editing the listbox directly)
03-08-2023 02:05 AM
perfect 🙂
03-08-2023 07:05 AM
Hi Altenback. Thank you for your suggestion. I appreciate it 😉 But double clicking with a popup menu will make it more difficult to make changes isn't that correct? I just want to make changes fast and easy.
About using tables for user input:
My purpose is to program an instrument. Water is dripping from a soil sample into a bottle.
One bottle is under the soil sample for a period specified in “Bottle time.”
When the bottle time elapses (“current bottle time”), a new bottle is automatically put under the soil sample and the “current bottle” is incremented with 1.
When the “current bottle “ is equal to the “Number of bottles” the active line (MCL value = MCL value +1) of the MCL is changed to the next line.. “Total time” is the time for all the bottles in the line (Number of bottles” x ”Bottle time”).
The user is only allowed to enter the columns “Number of bottles” and “Bottle time”. The other columns are controlled by the program.
The number of lines in the program can change from time to time.
If there are any better ways to solve my problem, I'm all ears! Please let me know. I would like to learn.😊😊
Michael
03-08-2023 09:19 AM - edited 03-08-2023 09:20 AM
@Michael.Koppelgaard wrote:
Hi Altenback. Thank you for your suggestion. I appreciate it 😉 But double clicking with a popup menu will make it more difficult to make changes isn't that correct? I just want to make changes fast and easy.
...
The user is only allowed to enter the columns “Number of bottles” and “Bottle time”. The other columns are controlled by the program.
If you count the number of clicks needed to edit the listbox, you'll be surprised that using the popup does not really cost you more time than editing the table directly. You can easily expand the popup to add controls for two entries (number of bottles, bottle time).
You could even have a 2D array where you can edit all rows (two columns) in one popup.
Since the popup is using using numeric integer controls, you can even use the increment/decrement buttons to quickly adjust with the mouse, no need to detour over the keyboard and no need to validate the input (you can set the valid range in the control properties).
If you allow editing of the listbox directly, you need to add a lot of backend code for full functionality (Only allow certain fields to be changed, also allow editing keys (such as backspace, enter, etc.) so the user can correct directly if e.g. 999 is accidentally entered instead of 9 or to end the entry with the return key.
Of course you could do some elaborate detection over which field the mouse is hovering and then detect the up/down arrows to increment/decrement that field, etc. Code won't be very nice and there will be many more places for bugs to hide.