Setting focus to a particular screen object

Hi.

If I have a screen with several screen objects (eg. buttons, text boxes, data grids etc.) is there a way to programmatically set focus to a particular object, for example from within CodeBehind or a class function?

Can the object Control Name be used for this purpose? I have seen mention in the documentation of using the object Control Name within CodeBehind, but have only found an example relating to SparkLines.

There appears to be a huge amount of functionality accessible using the Control Name … but virtually no documentation or example code describing usage.

Hi Greg,

When you want to take control of an object you can use the following code:
image

In this case it is a TTextBox, for button you will use TButton…, just press Ctrl+Space to see all possibilities, also the “text1” is the uid of the object and “a” is the control name.

So if you want to access all the methods from this object you can type “a.” in a new line and it will open a whole list.
image

In what situation do you want to use this focus? You can use this code below to get focus when starting the application in DisplayOpening().
image

Let us know if it works for you please.

Best Regards,
Tatsoft Team.

Thanks for the response Eduardo, which has been useful … although I still must admit that I am finding the .NET environment overall to be extremely cryptic. There seems to me to be a lot of assumed knowledge required, and little on-line to help those starting out.

If you can offer any advice on a related question, it would be appreciated.

What you have described above allows setting of keyboard focus.

I assume there is also a simple method available to tell when a particular object receives focus … but I have not been able to stumble on a successful approach despite a lot of searching. In particular, I have a DataGridWindow with control name “teststbl_grid” which is generally accessed after tabbing through a series of text boxes used for data entry.

I would simply like to know when focus is first obtained by the data grid. When this happens I will take particular action. If this can be determined within the CodeBehind for the screen that would be great, but any options would be appreciated.

Hi Greg,

Really sometimes you will need some online help, but our codes are in C# and VB.NET which are accessible languages, you can use Taks and Classes to executed some codes in parallel (multithreading concept), and you can also always think that it is Oriented Object Programming so you can treat everything as an object

About the focus, this code below shows you how to create an event that when DataGrid obtains focus a function is called (Got) and when lost focus another function is called (Lost). You can do the same to others objects.

Please, don’t hesitate to contact us if you have any questions.

Best Regards,
Tatsoft Team.