Bug? TreeView initial focus

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can use this code to explicitly set the focus:
B4X:
Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.RootPane.LoadLayout("1") 'Load the layout file.
   MainForm.Show
   For i = 1 To 10
     Dim ti As TreeItem
     ti.Initialize("", "Item " & i)
     TreeView1.Root.Children.Add(ti)
   Next
   CallSubDelayed3(Me, "SetFocus", TreeView1, 0)
End Sub

Private Sub SetFocus(tv As TreeView, index As Int)
   Dim jo As JavaObject = tv
   jo.RunMethodJO("getFocusModel", Null).RunMethod("focus", Array(index))
End Sub
 

Informatix

Expert
Licensed User
Longtime User
You can use this code to explicitly set the focus:
B4X:
Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.RootPane.LoadLayout("1") 'Load the layout file.
   MainForm.Show
   For i = 1 To 10
     Dim ti As TreeItem
     ti.Initialize("", "Item " & i)
     TreeView1.Root.Children.Add(ti)
   Next
   CallSubDelayed3(Me, "SetFocus", TreeView1, 0)
End Sub

Private Sub SetFocus(tv As TreeView, index As Int)
   Dim jo As JavaObject = tv
   jo.RunMethodJO("getFocusModel", Null).RunMethod("focus", Array(index))
End Sub
I tried this function but I didn't call it with CallSubDelayed. Without it, that does not work. Thanks for this solution.
 
Top