B4J Question Copy a cell value from a tableview

Timoune

Member
Hello,

I'm working to add copy function on a tableview, I found how to do for a line but now I'm searching for a cell. The idea is to offert the choice between copy the line or just the specified cell.

B4X:
Sub CopyCell_Action () 'Context Menu
    Dim mi As MenuItem = Sender
    Dim CopyRow(TVALLNbColumn - 1) As Object = TVALL.SelectedRowValues
    Dim TempString As String =""
     If mi.Text = "_Copy Cell" Then
        For i=0 To TVALLNbColumn - 1
            If i < TVALLNbColumn - 1  Then
                TempString=TempString&CopyRow(i)&";"
            Else
                TempString=TempString&CopyRow(i)
            End If
        Next
         fx.Clipboard.SetString(TempString)
    End If
End Sub
 

sorex

Expert
Licensed User
Longtime User
there doesn't seem to be a direct selected cell access method.

you can bypass it by temporary store the value and use it when the context menu item is clicked.

B4X:
dim cellValue as string

Sub btnCopyCell_MouseClicked (EventData As MouseEvent)
Log(CellValue)
End Sub

Sub tblData_SelectedCellChanged (RowIndex As Int, ColIndex As Int, Cell As Object)
CellValue=Cell
End Sub
 
Upvote 0

Timoune

Member
Thanks a lot it's working fine

B4X:
Sub TVALL_SelectedCellChanged (RowIndex As Int, ColIndex As Int, Cell As Object)
    Log(Cell)
    CellValue=Cell
    Log(CellValue)
End Sub

Sub CopyCell_Action () 'Context Menu
    Dim mi As MenuItem = Sender
     If mi.Text = "_Copy Cell" Then
         fx.Clipboard.SetString(CellValue)
    End If
End Sub
 
Upvote 0
Top