Android Question How can you programatically select a row in a tableview?

Steve Kirk

Member
Licensed User
Longtime User
Hi,

I'm working on an application in which several screens contain tableviews. At the moment when a screen containing a tableview appears for the first time no row is selected. I would like to be able to select the first row in the tableview programatically so that it appears selected when the user first sees the table. There should thus be no time when the table does not show a selected row. The intuitive way to do this would be to set the 'SelectedRow' property to an initial value. For example:

Dim tbvRecords as TableView
...
tbvRecords.SelectedRow = 0 'attempt to show the first row of tableview as selected

This, unfortunately, does not work. I receive an error message stating that 'SelectedRow' is read-only.
Is there some other way to do this? Perhaps by generating a click event if necessary? Thanks!
 

Steve Kirk

Member
Licensed User
Longtime User
Thanks! I didn't realize that there were two versions of the TableView class. At the moment I'm not sure which version I'm using but I imagine it must be the B4J version. I may put a similar post on that forum soon.
 
Upvote 0

Steve Kirk

Member
Licensed User
Longtime User
Hi,

Dim Table1 As Table
....
Dim rc As RowCol
rc.Row = 2
rc.Col = 1
Table1.SelectRow(rc)

I tried the sample code provided above in both my application and in the TableV1_29 sample application found on this site. In both cases I got an error message when I tried to compile and run the code. The error was:

Error compiling program
Error description: cannot access private member: selectrow

I imagine that this may be a B4J TableView vs standard TableView issue but, quite frankly, I don't understand the distinction or where the TableView class is located (in a library?). I did some sort of installation a while ago to get access to the 'Table' class and to be able to create 'Table' objects but I don't recall any of the details. How can I be sure I am dealing with B4J Tableviews?
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
The latest Table class version is 1.32.
And the code I posted works, because I tested it before posting it.

I asked you about B4J because you posted in the B4A forum about
Dim tbvRecords as TableView
But I don't know about any TableView view in B4A, but it does exist in B4J.
 
Upvote 0

Steve Kirk

Member
Licensed User
Longtime User
Hi Klaus,

Thanks again for your response. I've now got the programmatic row selection working properly. I was confused about a couple of things that caused problems. I mixed up the 'Table' class and the 'TableView' class - I thought they were the same thing but I now realize that they are different classes. I also incorrectly typed the required property as 'SelectedRow' instead of 'SelectRow' (there is a 'SelectedRows' property which I think led me astray).
Hopefully this post will save others from the same problems.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…