I have a textfield name stored in a variable displayed in a container control and the container control name is also stored in a variable.
Is there a way to set the focus to that textfield ?
I’m running OS X
I have a textfield name stored in a variable displayed in a container control and the container control name is also stored in a variable.
Is there a way to set the focus to that textfield ?
I’m running OS X
You can iterate the controls until finding the one whose name matches the one saved in the variable, I guess
Please, provide the code you used to create the variable.
thanks Javier for your tip,
found a solution iterating controls
Public Function GetControlByName(extends aWindow as window, aName as String) as RectControl
dim ctrl as RectControl
if aWindow<>nil then
For i as Integer=0 To aWindow.ControlCount-1
if aWindow.control(i) isa rectcontrol then
ctrl=RectControl( aWindow.control(i))
if ctrl<>nil then
If ctrl.Name=aName Then
return ctrl
End If
end if
end if
next
end if
return nil
End Function
This is a creative way to achieve the same goal:
First of all, a simple TextField and a PushButton will not work because I was not able to clear the Focus to that TextField (or forgot the how to).
Now:
a. Create a new Project,
b. Add a TextArea (to give it the focus),
If you place the TextArea order above the TextField, you do not have to set the code below.
(or simply place the TextArea in the window first, then place the TextField second.)
Add an Open Event to the window and put the code below in it to set the Focus to the TextArea:
Sub Open() Handles Open
// Set the focus to the TextArea
TextArea1.SetFocus
End Sub
c. Add a TextField you will name TF_Info
,
Add an Open Event to the TextField (called TF_Info
,) and put this code:
Sub Open() Handles Open
// Get a reference to this TextField
Ctrl_Ref_TF = Me
End Sub
d. Add a PushButton (for the visual feedback),
In the PushButton, add an Action Event and put the code below:
[code]Sub Action() Handles Action
// Control Names and References
//
// Get the Control Names and References of this PushButton
// and set the focus to it
//
Dim Ctrl_Name As String
// Get the TextFields Name
Ctrl_Name = Ctrl_Ref_TF.Name
// Check the TextFields Reference
If Ctrl_Ref_TF = Nil Then
MsgBox “An error occured” + EndOfLine + EndOfLine +_
“The TexTField Reference is Nil.”
Return
End If
// Set the Focus
Ctrl_Ref_TF.SetFocus
End Sub[/code]
Yes, this takes more code, but, as I wrote earlier, is a creative way to get what you really asked.
Now, you have two ways to code your project how you want to code (we do not know what you want to achieve, so I had to do all of the above to create a working example. You may not have to do all of that).