Moving Focus

Caravelle

Active Member
Licensed User
Longtime User
I must be missing something obvious, but I have a problem with setting and moving Focus from one control to another. There are 4 textboxes and a button. All I want to do is start with Focus in txt1, type something in, hit TAB or ENTER to move to txt2 and so on, ending up at Button1 which enters the data.

I haven't got beyond trying this on the desktop.

B4X:
Sub App_Start
   Form1.Show
   txt1.Focus
End Sub
...and when the form opens Focus is on txt2. Hmmmm. If I leave the form to type something here, the focus has mysteriously moved to txt4 when I get back. Hmmm.

I thought something like:
B4X:
Sub txt1_LostFocus
  txt2.Focus
End Sub

Sub txt2_LostFocus
  txt3.Focus
End Sub
would move the focus along, but it works with some boxes and not with others. <sigh>

Is there a way of simulating the Tab Order process found in other languages?

Thanks

Caravelle
 

klaus

Expert
Licensed User
Longtime User
With the Door library you can define TabStop and TabIndex for the different controls.
- TabStop defines if with the tab key the program stops at this control or if it jumps over
- with TabIndex you can define your tab order.

You can also define TabIndex with SendToBack in the right order in the IDE.

Attached an example program with the Door library.

Best regards.
 

Attachments

  • TabIndex.sbp
    1.6 KB · Views: 188

dlfallen

Active Member
Licensed User
Longtime User
I had the same problem in one of my programs. What I found was that Textbox1.focus (etc.) worked properly on the device even though it didn't work on the desktop.

You might try testing your code on the device (or emulator). One reason why I use the emulator - it's a lot easier to debug device bahavior.
 

Caravelle

Active Member
Licensed User
Longtime User
Thanks "dlfallen" - but actually I only want the program for my desktop. I have a set of sqlite databases spread across my local network, and B4PPC is excellent for creating neat, small, fast applets to read and update specific data with minimal clicking and typing. Yes, it might be handy to be able to link my iPAQ214 into the network wirelessly, but I haven't managed that yet.

It would have been helpful if the program Help on the .focus method explained that it works on the device only, if that is the case.

Thanks to Klaus for the pointer to the door library. I might have guessed, but I don't know much about this library yet. It looks like it's going to take three times as much coding to move the tabs along as to fetch answers from the database tables!

Thanks again.
Caravelle
 
Top