Android Question B4Xtable select one or more rows programmatically

Noelkman

Member
Licensed User
Longtime User
B4XTable is a really great extension and I use it a lot. Now I have the problem that I cannot select one ore more rows programmatically.
This example works great:
From select query:
    Dim rs As ResultSet = B4XTable1.sql1.ExecQuery("SELECT rowid from data")
    
    Do While rs.NextRow
        Selections.SelectedLines.Put(rs.GetLong("rowid"), "")
    Loop
    Selections.Refresh

where this one does not:
Programmatically:
    Selections.SelectedLines.Put(1, "")
    Selections.SelectedLines.Put(2, "")
    
    Selections.Refresh

What is the difference?
If I select the whole result (number of 115) in a loop it selects all rows just fine but if I select two rows it does nothing.
rs.GetLong("rowid") only returns a number right?
 

Mahares

Expert
Licensed User
Longtime User
What is the difference?
Here is my take: Because B4XTable is based on an in-memory SQLite database, the only way to return a value is to execute a SELECT query. Without running a query in your 2nd example, you have nothing. But, you bring up a great question. We will see if someone or Erel refutes my reasoning or not and gives a more valid answer.
 
Upvote 0

Noelkman

Member
Licensed User
Longtime User
The thing is that rs.GetLong("rowid") returns nothing else than a integer that ranges like in my case from 1 to 115
Instead of using the first example way we could go and use For i = 1 to 115 which is the same smell IMHO
I tried that but that does not work either. I don't get it.
 
Upvote 0

Noelkman

Member
Licensed User
Longtime User
I found it!
It has to be a type Long in fact. This is mandatory.
Solution:
' This works!
For i = 1 To 115
    Dim v As Long = i
    XSelections.SelectedLines.Put(v, "")
Next
XSelections.Refresh



' This does not!!!
For i = 1 To 115
    XSelections.SelectedLines.Put(i, "")
Next
XSelections.Refresh


B4X:
'Now if we write:

XSelections.SelectedLines.Put(1, "")

XSelections.SelectedLines.Put(2, "")

'it is not a long and therfor it is not working either. It has do be defined as such like

Dim v1 As Long = 1
Dim v2 As Long = 2

XSelections.SelectedLines.Put(v1, "")
XSelections.SelectedLines.Put(v2, "")

Isn't that crazy?

Maybe worth a new thread but what type is 'i' in a For - Next?
 
Upvote 0

Noelkman

Member
Licensed User
Longtime User
It is Int by default.

You can set its type with:
B4X:
Dim i As Long
For i = 1 To 115
XSelections.SelectedLines.Put(i, "")
Next

Cool, I didn't know that.

New glitch:
The 115 records are spread over 6 pages. If all of them are marked for selection like in my first post all of them are highlighted.
Now if I select some from the first visible page those are highlighted too.
But if I select some from lets say page 3 those are not highlighted.
Is it possible that this has something todo with the virtual list? That it is not completely created or so?
 
Upvote 0
Top