Display saved text in textbox

Hi community!

Simple question: I want to display a certain text in a textbox before the user enters anything into that textbox. So, rather than a hint in light font, I want the textbox already to be populated as if the user had already entered something.

Example: An app to keep track of stored ingredients:

Screen 1: The label for salt displays "5" (meaning 5 kilograms), the label for sugar displays "3" etc. These values change as the user uses the app. However, if they want to reset everything directly (or wants to start using the app for the first time and tell the app what they have in store, there is a Reset button that takes them to

Screen 2: Here, there are textboxes for each ingredient. Now, I want these textboxes to be populated with the latest data from Screen 1. The user can then make changes to any of the boxes and save the whole lot to be sent back to the corresponding labels in Screen 1.

Use virtual screens instead of actual screens.

You can save the values to global variables (1 if you initialize it in a list). You can change these values as needed in the first virtual screen.

The second virtual screen can contain TextBoxes, and this is only shown when a Button is pressed. You can update the values of the variable(s) when another Button is pressed (this one being inside the virtual screen).
If one field remains empty, the value for the corresponding category does not change.

Thanks a lot, Nishyanth, I am reading about the virtual screens and it does seem to be the better way of handling this (even though with just two screens planned, using real screens may not be much of a problem, right?)

Anyway, but what about having the existing data already displayed in the text boxes? I suppose that's not possible, perhaps?

Essentially, I want the functionality (not the design) of a spreadsheet, which has information saved for ever cell and DISPLAYED, and where the user can change whichever cell he wants to change.

If you are planning to use actual screens, you could use a TinyDB, or just send the values through the "open screen with start value" block. However, using virtual screens is the most straightforward path.

You'll need to populate the TextBoxes everytime a change is made, and obviously, when the screen is initialized (again, you will need a TinyDB or another database)
You can put these blocks in a procedure, and call this procedure during the events (when the submit button is clicked [only applies if you're working with virtual screens], when the screen is initialized).

I would love to give you blocks for this, but cannot, as I'm on my phone, at the moment.

Really appreciaete your time! I am already sending the data back and forth through TinyDB, using a procedure to save them all (even the one's that were not changed) on the edit screen (Screen2).

So really, the only thing I don't understand is how to, as you suggest, "populate the text boxes"

1 Like

How exactly are you storing the values in the TinyDB?

I think I have found a useful video. This one shows something very similar (at 3:45) using a list or dictionary. I will read more about how to use those

Perfect. Now, all you have to do, if you haven't already done so, is to make a set of blocks that gets the value for each tag from TinyDB, and set the corresponding TextBox's text to that. These blocks should be under the Screen1.Initialize event.

You could also include them in a procedure and call them from there, if you want to change it in other ways on the same screen.

Thanks, again!

Yes, I have that running. However, my question is about Screen2. So when the user switches to Screen2, I want the app to call the current names and values and populate the text boxes with those. Since these are textboxes, not labels, is that even possible at all?

If not, perhaps I need to try to replicate what the person in that video does. Mintue 3, second 45 of that video is pretty much the same thing that I want (just not for 2 data items but about 20)

Yes, you can do this through the "set TextBox.Text" block.
image

It works, thank you! I didn't know about that block yet

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.