following Klaus example, I would like to add some columns to my scrollview but I can't, in the SQL table the columns are present but I was not able to show them on the screen....
this is my code:
Tried to put this
But only the first 5 columns are always displayed!
this is my code:
B4X:
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim SQL1 As SQL : SQL1 = Main.SQL1
Dim Codcli As String : CodCli = Clienti.Codcli
Dim RagSoc As String : RagSoc = Clienti.RagSoc
Dim TxtIdOrd As EditText
Dim TxtDataOrd As EditText
Dim TxtOraOrd As EditText
Dim BtnAddArt As Button
Dim BtnModArt As Button
Dim BtnDelArt As Button
Dim BtnAnnulla As Button
Dim BtnConferma As Button
Dim BtnListOrd As Button
Dim BtnCli As Button
Dim scvList As ScrollView
Dim Header As Panel
Dim Table As Panel
Dim SelectedItems As List
Dim NumberOfRows As Int : NumberOfRows=0
Dim PreviousRow As Int : PreviousRow=-1
Dim NumberOfVisibleRows As Int
Dim NumberOfColumns As Int : NumberOfColumns = 7 'will be overwritten when loading from CscvList file.
Dim RowHeight, RowHeight_1, RowLineWidth As Int
RowLineWidth = 0dip
RowHeight = 30dip
RowHeight_1 = RowHeight - RowLineWidth
Type RowCol (Row As Int, Col As Int)
Dim LineColor As Int : LineColor = Colors.Black
Dim ColumnWidth(7) As Int
Dim ColumnWidth_1(7) As Int
Dim ColLineWidth As Int : ColLineWidth = 0dip
Dim SelectedRowColor As Int : SelectedRowColor=Colors.RGB(250,215,0) 'RGB(255,196,196)
Dim SelectedCellColor As Int : SelectedCellColor=Colors.RGB(250,215,0)
'Table settings
Dim HeaderColor(7) As Int
HeaderColor(0)=Colors.Gray '.RGB(0,255,255)
HeaderColor(1)=Colors.Gray '.RGB(0,255,255)
HeaderColor(2)=Colors.Gray '.RGB(0,160,160)
HeaderColor(3)=Colors.Gray '.RGB(0,160,160)
HeaderColor(4)=Colors.Gray '.RGB(0,160,160)
HeaderColor(5)=Colors.Gray '.RGB(0,160,160)
HeaderColor(6)=Colors.Gray '.RGB(0,160,160)
Dim HeaderFontColor(7) As Int
HeaderFontColor(0)=Colors.White
HeaderFontColor(1)=Colors.White
HeaderFontColor(2)=Colors.White
HeaderFontColor(3)=Colors.White
HeaderFontColor(4)=Colors.White
HeaderFontColor(5)=Colors.White
HeaderFontColor(6)=Colors.White
Dim CellColor(7) As Int
CellColor(0) = Colors.White
CellColor(1) = Colors.White
CellColor(2) = Colors.White
CellColor(3) = Colors.White
CellColor(4) = Colors.White
CellColor(5) = Colors.White
CellColor(6) = Colors.White
Dim FontColor(7) As Int
FontColor(0) = Colors.Black
FontColor(1) = Colors.Black
FontColor(2) = Colors.Black
FontColor(3) = Colors.Black
FontColor(4) = Colors.Black
FontColor(5) = Colors.Black
FontColor(6) = Colors.Black
Dim FontSize(7) As Float
FontSize(0) = 10
FontSize(1) = 10
FontSize(2) = 10
FontSize(3) = 10
FontSize(4) = 10
FontSize(5) = 10
FontSize(6) = 10
Dim Alignment(7) As Int
Alignment(0) = Gravity.LEFT
Alignment(1) = Gravity.LEFT
Alignment(2) = Gravity.CENTER_HORIZONTAL
Alignment(3) = Gravity.CENTER_HORIZONTAL
Alignment(4) = Gravity.CENTER_HORIZONTAL
Alignment(5) = Gravity.RIGHT
Alignment(6) = Gravity.CENTER_HORIZONTAL
Dim TxtCodCli As EditText
Dim TxtRagSoc As EditText
Dim TxtTotImp As EditText
Dim TxtTotOma As EditText
Dim TxtTotIva As EditText
Dim TxtTotOrd As EditText
End Sub
B4X:
Sub SQLReadTable
' Reads the SQL data base
Dim i As Int
Dim Cursor1 As Cursor
Cursor1 = SQL1.ExecQuery("SELECT IdArt,DesArt,Um,QtaOrd,QtaOma,ImpUni,AliIva from ORDINI where IdOrd = '" &TxtIdOrd.Text &"'")
Dim row(NumberOfColumns) As String
row(0)="Codice"
row(1)="Descrizione"
row(2)="Um"
row(3)="Qtà"
row(4)="Oma"
row(5)="Imp. Unit."
row(6)="Iva"
SetHeader(row)
NumberOfRows=0
For i = 0 To Cursor1.RowCount - 1
Dim row(NumberOfColumns) As String
Cursor1.Position = i
row(0)=Cursor1.GetString("IdArt")
row(1)=Cursor1.GetString("DesArt")
row(2)=Cursor1.GetString("Um")
row(3)=Cursor1.GetString("QtaOrd")
row(4)=Cursor1.GetString("QtaOma")
row(5)=Cursor1.GetString("ImpUni")
row(6)=Cursor1.GetString("AliIva")
AddRow(Row)
Next
Cursor1.Close
' CalcolaTotale
End Sub
Sub SetHeader(Values() As String)
' Set the headers values
' ColumnWidth(0)=70dip
' ColumnWidth(1)=90dip
' ColumnWidth(2)=25dip
' ColumnWidth(3)=25dip
' ColumnWidth(4)=25dip
' ColumnWidth(5)=60dip
' ColumnWidth(6)=25dip
Dim ColWidth As Int
If header.IsInitialized Then Return 'should only be called once
header.Initialize("")
ColWidth=0
For i = 0 To NumberOfColumns - 1
Dim l As Label
l.Initialize("header")
l.Text = values(i)
l.Gravity = Alignment(i)
l.TextSize = FontSize(i)
l.Color = HeaderColor(i)
l.TextColor = HeaderFontColor(i)
l.Tag = i
header.AddView(l, ColWidth, 0, ColumnWidth_1(i), RowHeight_1)
ColWidth=ColWidth+ColumnWidth(i)
Next
Activity.AddView(header, scvList.Left, scvList.Top - RowHeight, scvList.Width, RowHeight)
End Sub
Sub SetCell(Row As Int, Col As Int, Value As String)
' Sets the value of the given cell
GetView(Row, Col).Text = value
End Sub
Sub AddRow(Values() As String)
' Adds a row to the table
Dim ColWidth As Int
If values.Length <> NumberOfColumns Then
Log("Wrong number of values.")
Return
End If
ColWidth=0
For i = 0 To NumberOfColumns - 1
Dim l As Label
l.Initialize("cell")
l.Text = values(i)
l.Gravity = Alignment(i)
l.TextSize = FontSize(i)
l.TextColor = FontColor(i)
l.Color=CellColor(i)
Dim rc As RowCol
rc.Initialize
rc.Col = i
rc.Row = NumberOfRows
l.Tag = rc
Table.AddView(l, ColWidth, RowHeight * NumberOfRows, ColumnWidth_1(i), RowHeight_1)
ColWidth=ColWidth+ColumnWidth(i)
Next
NumberOfRows=NumberOfRows+1
Table.Height = NumberOfRows * RowHeight
End Sub
Sub GetView(Row As Int, Col As Int) As Label
' Returns the label in the specific cell
Dim l As Label
l = Table.GetView(Row * NumberOfColumns + Col)
Return l
End Sub
Tried to put this
B4X:
ColumnWidth(0)=70dip
ColumnWidth(1)=90dip
ColumnWidth(2)=25dip
ColumnWidth(3)=25dip
ColumnWidth(4)=25dip
ColumnWidth(5)=60dip
ColumnWidth(6)=25dip
But only the first 5 columns are always displayed!