B4J Question TableView.SelectedRowValues

Blueforcer

Well-Known Member
Licensed User
Longtime User
Hello,

the documentation says about "SelectedRowValues":
"Gets the values of the selected row or sets the selected row based on the given values."

Now i want to scroll to the row where column(X) = User

I tried this but not working
B4X:
ticketTable.SelectedRowValues(3)="UserXY"

How can i do this?
 

Daestrum

Expert
Licensed User
Longtime User
You need to search the items in the table, SelectedRowValues() only allows you to read or update the selected row.

Small example how to search the data for what you want (Probably could be written better but I'm too hot at present :) )
B4X:
Sub Process_Globals
 Private fx As JFX
 Private MainForm As Form
 Dim tableview1 As TableView
End Sub
Sub AppStart (Form1 As Form, Args() As String)
 MainForm = Form1
 'MainForm.RootPane.LoadLayout("Layout1") 'Load the layout file.
 MainForm.Show
 tableview1.Initialize("tv1") ' manually build the table
 tableview1.SetColumns(Array("one","two","three"))
 tableview1.SetColumnWidth(0,100)
 tableview1.SetColumnWidth(1,100)
 tableview1.SetColumnWidth(2,100)
 MainForm.RootPane.AddNode(tableview1,0,0,400,500)
 For a = 0 To 5  ' put some data in the table
  tableview1.Items.Add(Array(a,a*2,a*5))
 Next
' the search bit is from here down
 Dim row() As Object
 Dim col as Int = 2 ' the column I want to search
 Dim what As Object = 25 ' what I want to search for
 Dim cnt As Int = 0
 row = tableview1.Items.Get(cnt)
 Do While row(col)<>what  'search third column for value
  cnt = cnt + 1
  If cnt = tableview1.Items.Size Then Exit
  row = tableview1.Items.Get(cnt)
  If row(col)=what Then 
   Exit 
  Else
    row(0) = "not found"
  End If
 Loop
 Log(row(0)) ' display first column value or 'not found'
End Sub
 
Upvote 0

Blueforcer

Well-Known Member
Licensed User
Longtime User
Awesome..thx!

this is my working code now:

B4X:
 public Sub scrollTo (s As String)
    Dim row() As Object
    Dim col As Int = 3 '
    Dim what As Object = s
    Dim cnt As Int = 0
    row = ticketTable.Items.Get(cnt)
    Do While row(col)<>what
        cnt = cnt + 1
        If cnt = ticketTable.Items.Size Then Exit
        row = ticketTable.Items.Get(cnt)
        If row(col)=what Then
            Exit
        End If
    Loop
    ticketTable.SelectedRow=cnt
End Sub
 
Upvote 0

Daestrum

Expert
Licensed User
Longtime User
The only problem I can see with your implementation is, if the item is not found, the last row will be selected.
 
Upvote 0
Top