Sub miScriptCopyGridData_Action
mdlShared.CopyGridDataToClipbard(tblScript, TAB, True)
End Sub
Sub CopyGridDataToClipbard(Table As TableView, DelimiterChar As String, IncludeHeader As Boolean)
'Data
Dim lData As List
lData.Initialize
Dim DataForClipBoard As String
For i = 0 To Table.Items.Size - 1 '--------------------
Dim s As String
Dim aRow() As Object = Table.Items.Get(i)
For iI = 0 To aRow.Length - 1
If aRow(iI) Is Label Then
s = s & GetlabelText(aRow(iI)).Text & DelimiterChar
Else
s = s & aRow(iI) & DelimiterChar
End If
Next
lData.Add(s)...
Dim TV As TableView
Dim RowData As List
RowData.Initialize
For i = 0 To TV.Items.Size - 1
Dim Row() As Object = TV.Items.Get(i)
Dim this_row(Row.Length) As String
For k = 0 To Row.Length - 1
'If the table items are just strings:
this_row(k) = Row(k).As(String)
'If each cell is defined as a kind of node:
If Row(k) Is Label Then
this_row(k) = Row(k).As(Label).Text
Else If Row(k) Is TextField Then
this_row(k) = Row(k).As(TextField).Text
'And so on
End If
Next
RowData.Add(this_row)
Next
You can extract the contents of the TableView in an organized List variable as follows:
B4X:Dim TV As TableView Dim RowData As List RowData.Initialize For i = 0 To TV.Items.Size - 1 Dim Row() As Object = TV.Items.Get(i) Dim this_row(Row.Length) As String For k = 0 To Row.Length - 1 'If the table items are just strings: this_row(k) = Row(k).As(String) 'If each cell is defined as a kind of node: If Row(k) Is Label Then this_row(k) = Row(k).As(Label).Text Else If Row(k) Is TextField Then this_row(k) = Row(k).As(TextField).Text 'And so on End If Next RowData.Add(this_row) Next
Headers can be extracted from TV.GetColumnHeader(index)
Now each item in RowData will contain all the data in one of the rows (as a string array).
To get them into clipboard, these could work:
1. sort them into plain text, using tabs and new line character and then use fx.Clipboard.SetString
2. output the results into an Excel file (using jExcel to create the file) and then use fx.Clipboard.SetFiles to copy the file into clipboard.
Hope this helps!
Sub CopyGridDataToClipbard(Table As TableView, DelimiterChar As String, IncludeHeader As Boolean)
'Data
Dim lData As List
lData.Initialize
Dim DataForClipBoard As String
For i = 0 To Table.Items.Size - 1 '--------------------
Dim s As String
Dim aRow() As Object = Table.Items.Get(i)
For iI = 0 To aRow.Length - 1
If aRow(iI) Is Label Then
s = s & GetlabelText(aRow(iI)).Text & DelimiterChar
Else
s = s & aRow(iI) & DelimiterChar
End If
Next
lData.Add(s)
Next
'header
If IncludeHeader = True Then
Dim hdr As String
For i = 0 To Table.ColumnsCount - 1
hdr = hdr & Table.GetColumnHeader(i) & DelimiterChar
Next
DataForClipBoard = hdr & CRLF
End If
For d = 0 To lData.Size - 1
DataForClipBoard = DataForClipBoard & lData.Get(d) & CRLF
Next
fx.Clipboard.SetString( DataForClipBoard)
End Sub
Sub miScriptCopyGridData_Action
mdlShared.CopyGridDataToClipbard(tblScript, TAB, True)
End Sub
Sub CopyGridDataToClipbard(Table As TableView, DelimiterChar As String, IncludeHeader As Boolean)
'Data
Dim lData As List
lData.Initialize
Dim DataForClipBoard As String
For i = 0 To Table.Items.Size - 1 '--------------------
Dim s As String
Dim aRow() As Object = Table.Items.Get(i)
For iI = 0 To aRow.Length - 1
If aRow(iI) Is Label Then
s = s & GetlabelText(aRow(iI)).Text & DelimiterChar
Else
s = s & aRow(iI) & DelimiterChar
End If
Next
lData.Add(s)
Next
'header
If IncludeHeader = True Then
Dim hdr As String
For i = 0 To Table.ColumnsCount - 1
hdr = hdr & Table.GetColumnHeader(i) & DelimiterChar
Next
DataForClipBoard = hdr & CRLF
End If
For d = 0 To lData.Size - 1
DataForClipBoard = DataForClipBoard & lData.Get(d) & CRLF
Next
fx.Clipboard.SetString(DataForClipBoard)
lData.Clear
End Sub