Same text fields must she the same text, how?

So this must be an easy task, but i feel I have a blind spot here…

I am using the same text field a couple of times in the desktop app I am building. And I would like to see the same text that is being filled in at all the text fields. So if the user makes a change in one field, that change must show up in the other fields as well.

I tried to grasp the .text value of the field in a variable and to set the .text value of the other fields with this variable, but this doesn’t work. How can I make this happen?

Hi @André_van_Haren

Can you share with us the code you’re using or even the project? That way it would be easier to help you to understand what may be wrong :slight_smile:

The code is very simple, but maybe not used correctly. This is the code I placed in the textfield TextChange window:

var StoryConcept as string
txtConcept.text = StoryConcept

After that I thought I could set the other similar textfields with the value of this variable StoryConcept, but this doesn’t work this way, it seems.

This is a way of doing it (among others): TextFields-Notification-Receiver.xojo_binary_project.zip

Thanks. The project doesn’t run, it gives an error. But I came around the same it by using a Button to send the info to all the text fields:
txtConcept2.value = txtConcept.Value etc

A solution I could also think of is that when the field receives a return key, it could run this same script. I believe this is how it worked in Filemaker which I used for many years. I recently picked up Xojo again, so I am little rusty…

Try to download it again… I did some changes to the name of the controls (but not to the code referring to them). Now it is fixed… it was too fast! :smiley:

nope, sorry :slight_smile:
Window1.Opening, line 4
Type “Window1.Window1” has no member named “ControlAt”
If Me.ControlAt(i) IsA DataReceiver Then

What version of Xojo are you using?

You don’t need an intermediate variable to do this.

Double-click the textfield and add an Event Handler for “TextChanged”
Inside that event, set all the other fields’ .Text property to txtConcept.text

Every time your textfield is changed by the user, the other textfields will now update.

If you’d like to use a variable to do it, the problem you might be running into is that based on the place that you declare the variable, it goes out of scope by the time you want to use it. To get around that, add a property of type String to your window, and store the value in that property instead of a variable local to a particular event handler.

2019 release 3.2

That explains it… the project I uploaded to Dropbox is 2022r2 (API 2.0). If you want, just to learn how, you can download the latest release from Xojo: Downloads

thanks. I am still a starter in Xojo so things cannot be too complicated, otherwise I have no idea what I am doing. I solved it by placing a button next to every text field which then updates all the other text fields with this code:

txtConcept.text = txtConcept2.text

Problem with a newer version is that I cannot use it for Building unless I pay again 140 dollars. Thanks though.

I found an even easier way to get what I want by using the LostFocus Event handler on the text fields which then run the script to change the other text fields. I also noticed that hitting the return key does the same, so I don’t even need the buttons.

Try to find info in Variable Scopes, you cant use that variable outside that event.
But Why you dont write the rest of the code right there?

that was all the code I had…

Simplest way to go would be to set all the textfields in a control set, and use the TextChange event to set all the members with the .text content.