How to click one cell in ScrollView table but get the value from a different cell on

Penfound

Active Member
Licensed User
Longtime User
Sub Cell_Click
If ThereIsOneCellSelected Then
Dim rc As RowCol
Dim l As Label
l = Sender
l.Color = CellColor
ThereIsOneCellSelected = False
Else
Dim rc As RowCol
Dim l As Label
SR = rc.Row
SC = rc.Col
ThereIsOneCellSelected = True
l = Sender
rc = l.Tag
getBookColour = l.Text
SelectRow(rc)
Activity.Title = l.text & " " & GetRecordNumber
End If
End Sub

My table has 5 column 0 to 4 Using Cell_Click I can easily retrieve the data in the cell '2' as in l.text and calling a modified SelectRow I change the colour of the selected cell. The "ThereIsOneCellSelected" is to allow me to use the same buttons for different functions.

I am struggling to find a way of getting the data from another cell on the same row, row 0.

Sub SelectRow(rc As RowCol)
Dim col As Int
Dim k As Label
'Removes the color of previously selected row
If SelectedRow > -1 Then
For col = 0 To NumberOfColumns - 1
Getview(SelectedRow, col).Color = CellColor
Next
End If
SelectedRow = rc.Row
'Sets the color of the selected row and selected cell
Getview(rc.Row, 2).Color = SelectedCellColor
k = Getview(SelectedRow,0)
GetRecordNumber = k.text
Activity.Title = getBookColour & " at " & GetRecordNumber
End Sub

Although I've called the variable GetRecordNumber it is a reference to the Catalogue Number in my db. However, what this code retreives is the row number in terms of the recordset it is working with, not the data actually in the cell.

I need that data so I can call an update routine to change the value of the 'book' in the db.

It would be wonderful if we could could change the Sender value so it would reference the cell two columns back
 

klaus

Expert
Licensed User
Longtime User
Unfortunately you don't give enough information to give you a concrete answer.
How is the ScrollView populated ?

If you posted your project as a zip file it would be easier to help you.

You could also have a look at the SQLExample in the User's Guide.

Best regards.
 
Upvote 0

Penfound

Active Member
Licensed User
Longtime User
Sorry - I think I have the whole project zipped here now.

I'm not sure that it worked - seemed rather large.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
At least a smaller project that shows the problem.
It's much easier to help having a project we could test too and to find where the problem is and sending you a working project back.
That's the way how I prefer to help.

Best regards.
 
Upvote 0

Penfound

Active Member
Licensed User
Longtime User
I've found a way of showing you:)

If you use the SQL Example app and when it loads click on any cell in the LastName field, the Title bar shows the co-ordinates and the 'Value' of the text in the selected cell.

If you now click the header for firstname and then click on a LastName you will find that the co-ordinates are correct but the 'Value' is wrong.

This is part of my problem. the other part is that having selected, say, DUMOULIN I need that value plus the value of 20 from the ID column.

Cheers
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Thank you for reporting this error.
The attached version is corrected.
There was a ClearAll call missing before reloading the database.

To access a cell in a given column for a given row depends on how you populate the ScrollView.Panel.
If you populate it only with Labels like in the SQLExample you can get a given cell with following code :
B4X:
Sub GetView(Row As Int, Col As Int) As Label
    'Returns the label in the specific cell
    Dim l As Label
    
    l = scvPersons.Panel.GetView(Row * NumberOfColumns + Col)
    Return l
End Sub
The cell in the first column, Col = 0 :
B4X:
Dim l As Label    
l = GetView(Row, 0)
Best regards.
 

Attachments

  • SQLExample.zip
    14.6 KB · Views: 295
Last edited:
Upvote 0
Top