B4J Question Autoscroll horrizontal bar in a tableview

micro

Well-Known Member
Licensed User
Longtime User
Hi to all
It's possible get a horizontal bar autoscroll in a tableview when I move from one cell to another horizontally with the TAB key and these are not visible?
Thanks
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
The table is scrolled automatically when you change the selected item:

test.gif



B4X:
Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.RootPane.LoadLayout("1") 'Load the layout file.
   MainForm.Show
   TableView1.SetColumns(Array("a", "b", "c", "d", "e"))
   TableView1.SingleCellSelection = True
   For i = 1 To 1000
       TableView1.Items.Add(Array(i, i, i, i, i))
   Next
End Sub

I guess that you are not changing the selected item.
 
Upvote 0

micro

Well-Known Member
Licensed User
Longtime User
The table is scrolled automatically when you change the selected item:
Ok erel certainly, but this is a editable tableview (my project under development) and the cell is not raised because every
cell contains component as textfield, datapicker, ceckbox, combobox and more..

Thanks
 
Upvote 0

micro

Well-Known Member
Licensed User
Longtime User
I activate the cell but it does not work.
In the FocusChanged (texfield event) I added
B4X:
tv.SelectCell(row, col)
and i see that it is active, but also if I press the
TAB key not shakes automatically.
if it is possible to move the bar horizontally from code
it's better.
Thanks
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can modify the horizontal scroll bar value with this code:
B4X:
Sub Process_Globals
   Private fx As JFX
   Private MainForm As Form
   Private TableView1 As TableView
   Private HorizontalScrollBar As JavaObject
End Sub

Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.RootPane.LoadLayout("1") 'Load the layout file.
   MainForm.Show
   TableView1.SetColumns(Array("a", "b", "c", "d", "e"))
   TableView1.SingleCellSelection = True
   For i = 1 To 1000
       TableView1.Items.Add(Array(i, i, i, i, i))
   Next
   HorizontalScrollBar = FindHorizontalScrollBar(TableView1)
   Log(HorizontalScrollBar)
End Sub

Sub FindHorizontalScrollBar (tv As TableView) As JavaObject
   Dim jo As JavaObject = tv
   Dim bars() As Object = jo.RunMethodJO("lookupAll", Array(".scroll-bar")).RunMethod("toArray", Null)
   For Each bar As JavaObject In bars
       Dim orientation As String = bar.RunMethod("getOrientation", Null)
       If orientation = "HORIZONTAL" Then
           Return bar
       End If
   Next
   Return Null
End Sub

Sub MainForm_MouseClicked (EventData As MouseEvent)
   Dim MinValue As Double = HorizontalScrollBar.RunMethod("getMin", Null)
   Dim MaxValue As Double = HorizontalScrollBar.RunMethod("getMax", Null)
   Dim value As Double = (MinValue + MaxValue) / 2 'must be double
   HorizontalScrollBar.RunMethod("setValue", Array(value))
End Sub
 
Last edited:
Upvote 0
Top