Gridline in Tableview using scrollview

junaidahmed

Well-Known Member
Licensed User
Longtime User
As I am using Tableview to display record like grid format,it works fine but only thing is no grid line.pls advise how to use gridline for tableview using scrollview
 

nemethv

Member
Licensed User
Longtime User
I see that a) you didn't initialize the label 'L' in the subroutine and
b) even if you did, I don't see how you could read a latest label, since you write it after you write label0.

I think you should change the for loop as follows:

Hi,

Thanks for that.
Apparently the line

B4X:
If i = 0 AND Table.GetView(rc.Row * NumberOfColumns + 1).Text = "Something" Then L.Color = Colors.Red

is unhappy about the .text part as that element cannot have it's text part queried. ("unknown member")

Also re initialising L, is it just a simple L.initialize?
 
Upvote 0

nemethv

Member
Licensed User
Longtime User
Almost perfect :)
Except for that now since we're doing a step-1 all the cols are brought in the wrong way around, so what's supposed to be in the first place is the last....

Wouldn't it be possible to do something like a 'modifyView' to go back after drawing the table and say if in each row Col1 = 'Sth' then Col0 should be red?
 
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
Except for that now since we're doing a step-1 all the cols are brought in the wrong way around, so what's supposed to be in the first place is the last..
Sorry, but I don't really understand what you are meaning.

Wouldn't it be possible to do something like a 'modifyView' to go back after drawing the table and say if in each row Col1 = 'Sth' then Col0 should be red?
Yes, it would be possible, but why not doing it directly when you fill the table.

It would be easier if you posted your project as a zip file (IDE menu Export As Zip) or at least a smaller project that shows the problem.

Best regards.
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
A grid with some rows and columns, with the color of label at first column changed when specific text is found in a specific column. Perhaps this helps.
 

Attachments

  • labcolortest.zip
    6.5 KB · Views: 438
Upvote 0

xavcor75

Member
Licensed User
Longtime User
Remove lines

Hi, this table is perfect for my app, thanks. Now I'm trying to add a sub to remove a entire row, so I remove all the views of the selected row, therefore I need to redraw all the rows below and its data to fill the spaces left by the row eliminated. Have someone already implemented a similar process? Is there a better solution? Thanks in advanced.

Pd. Sorry my english is very poor!
 
Upvote 0

GMan

Well-Known Member
Licensed User
Longtime User
Hoi Klaus,
is it possible to make the colum as small as the smallest entry ?
Not EACH ;-) - hope you mentioned what i meant
 
Upvote 0

TheFalcon

Active Member
Licensed User
Longtime User
Good Night, and sorryfor my English, do not ye express both use translator.
I'm using your example of table.
But instead of having the CSV file already generated in the dirassets, what genre I in defaultexternal, pulling data from SQL, the problem is that I get separated by "," does not create tables me, but if I add that file to project and genre from dirassets if I generate them. I would appreciate any guidance.

I generate csv using this code:


B4X:
cursor1 = SQL1.ExecQuery("SELECT * FROM Diario")
For i = 0 To cursor1.RowCount - 1
cursor1.Position = i

'con estas lineas metemos los datos en distintas variables para luego cargarlos juntos.
fecha_informe = cursor1.GetString("Fecha") 'pasa el dato recogido a la variable dato que es string
peso_informe = cursor1.GetString("Peso")
tipo_informe = cursor1.GetString("Tipo")

'aqui añadimos los datos separados por coma con lo cual las lineas serian   FECHA,PESO,TIPO  , para luego cargar ne listview
tabla.Add(Array As String(fecha_informe & "," & peso_informe & "," & tipo_informe)) ' aqui lo añadimos a la lista TABLA
  Next
     
     'con esto guardariamos un archivo en el directorio de la aplicacion con el nombre de informe.csv
Dim sa As StringUtils ' Libreria que hay que añadir
       sa.SaveCSV(File.DirDefaultExternal,"informes.csv",",",tabla)

I load it using your own code, but instead of loading it from the complimentary assets defaultexternal
 

Attachments

  • imagen1.png
    imagen1.png
    12.1 KB · Views: 306
Upvote 0

klaus

Expert
Licensed User
Longtime User
Do you need the csv file or is it an intermediate file to load inot the table.
This example is an old one, did you have a look at the Flexible Table Class where you can fill a table directly from a SQLite database.

This line is wrong:
tabla.Add(ArrayAsString(fecha_informe & "," & peso_informe & "," & tipo_informe))
it should be
tabla.Add(ArrayAsString(fecha_informe, peso_informe, tipo_informe))
 
Upvote 0

Massimiliano

Member
Licensed User
Longtime User
This is a great solution! Much better than my suggestion..
I'm using this great solution and it's working fine!
However I'm having some problems with the grid refresh (when rows decrease) if manifest targetSdkVersion >= (SDK) 14 and hardwareAccelerated is set to "false".
Did it ever happened to you? I'm using B4A v4.30

Many thanks
 
Upvote 0

Massimiliano

Member
Licensed User
Longtime User
What exactly is the problem ?
Do you adjust the ScrollView.Panel.Height ?
You may add one or two DoEvenets lines after the Height change.
What exactly is the problem ?
Do you adjust the ScrollView.Panel.Height ?
You may add one or two DoEvenets lines after the Height change.

Hi Klaus, thank you,
give a look at this example
It doen't work for me until i turn on hardware acceleration or target sdk version < 14 in the manifest file
 
Upvote 0

Massimiliano

Member
Licensed User
Longtime User
Sub Process_Globals
End Sub

Sub Globals
Dim TMR As Timer

Dim TH1 As TabHost

Dim THEX As TabHostExtras

Dim SV1, SV2, SV3 As ScrollView
Dim P1, P2, P3 As Panel
Dim T1, T2, T3 As Panel

Dim Header As Panel

Dim h1() As String
Dim h2() As String
Dim h3() As String

Dim i1() As Int
Dim i2() As Int
Dim i3() As Int

Dim RowHeight As Int
Dim HeaderColor, LineColor, CellColor, FontColor, HeaderFontColor As Int
Dim RowLineBorder, ColLineBorder As Int
Dim FontSize As Float
Dim Alignment As Int

RowLineBorder = 1dip
ColLineBorder = 1dip
RowHeight = 20dip
FontSize = 8
Alignment = Gravity.CENTER
LineColor = Colors.DarkGray
CellColor = Colors.Black
FontColor = Colors.White
HeaderColor = Colors.LightGray
HeaderFontColor = Colors.Black
End Sub

Sub Activity_Create(FirstTime As Boolean)
TH1.Initialize("TH1")
THEX.setTabHeight(TH1, 100%y)
THEX.setTabContentViewPadding(TH1, 0, 0, 0, 0)

Activity.AddView(TH1, 0, 0, 100%x, 100%y)

P1.Initialize("")
P2.Initialize("")
P3.Initialize("")

TH1.AddTab2("TAB1", P1)
TH1.AddTab2("TAB2", P2)
TH1.AddTab2("TAB3", P3)

h1 = Array As String("#", "COL1", "COL2", "COL3", "COL4", "COL5", "COL6", "COL7")
h2 = Array As String("#", "COL1", "COL2", "COL3", "COL4", "COL5")
h3 = Array As String("#", "COL1", "COL2", "COL3", "COL4", "COL5", "COL6")

SV1.Initialize(0)
SV2.Initialize(0)
SV3.Initialize(0)

P1.AddView(SV1, 0, RowHeight + RowLineBorder * 2, TH1.Width - (h1.Length + 2) * ColLineBorder, TH1.Height - THEX.getTabHeight(TH1) - RowHeight - RowLineBorder * 2 - 10dip)
P2.AddView(SV2, 0, RowHeight + RowLineBorder * 2, TH1.Width - (h2.Length + 2) * ColLineBorder, TH1.Height - THEX.getTabHeight(TH1) - RowHeight - RowLineBorder * 2 - 10dip)
P3.AddView(SV3, 0, RowHeight + RowLineBorder * 2, TH1.Width - (h3.Length + 2) * ColLineBorder, TH1.Height - THEX.getTabHeight(TH1) - RowHeight - RowLineBorder * 2 - 10dip)

T1 = SV1.Panel
T2 = SV2.Panel
T3 = SV3.Panel

T1.Color = LineColor
T2.Color = LineColor
T3.Color = LineColor

i1 = Array As Int(SV1.Width * 0.05, SV1.Width * 0.12, SV1.Width * 0.15, SV1.Width * 0.15, SV1.Width * 0.15, SV1.Width * 0.10, SV1.Width * 0.14, SV1.Width * 0.14)
i2 = Array As Int(SV2.Width * 0.05, SV2.Width * 0.30, SV2.Width * 0.25, SV2.Width * 0.15, SV2.Width * 0.10, SV2.Width * 0.15)
i3 = Array As Int(SV3.Width * 0.05, SV3.Width * 0.175, SV3.Width * 0.175, SV3.Width * 0.15, SV3.Width * 0.15, SV3.Width * 0.15, SV3.Width * 0.15)

SetHeader(SV1, P1, h1, i1)
SetHeader(SV2, P2, h2, i2)
SetHeader(SV3, P3, h3, i3)

TMR.Initialize("TMR", 1000)
End Sub

Sub Activity_Resume
TMR.Enabled = True
End Sub

Sub Activity_Pause(UserClosed As Boolean)
TMR.Enabled = False
End Sub

Sub TMR_Tick
FillGrid
End Sub

Sub FillGrid

' RANDOM FILL TEST
Dim i As Int
Dim j As Int

ClearPanel(T1)
j = Rnd(0, 9)
For i = 0 To j
AddRow(T1, Array As String(j, T1.NumberOfViews, T1.Height, P1.Height, i, i, i, i), i1)
Next

End Sub

Sub ClearPanel(PanelName As Panel)
PanelName.RemoveAllViews
PanelName.Height = 0
End Sub

Sub AddRow(PanelName As Panel, Values() As String, ColumnWidth() As Int)
Dim lastRow As Int = PanelName.NumberOfViews / Values.Length
Dim col As Int
For col = 0 To Values.Length - 1
Dim lbl As Label
lbl.Initialize("L")
lbl.Text = Values(col)
lbl.Gravity = Alignment
lbl.TextSize = FontSize
lbl.TextColor = FontColor
lbl.Color = CellColor
PanelName.AddView(lbl, GetColLeft(ColumnWidth, col), (RowHeight + RowLineBorder) * lastRow, ColumnWidth(col) - ColLineBorder, RowHeight)
Next
PanelName.Height = (RowHeight + RowLineBorder) * (lastRow + 1)
End Sub

Sub SetHeader(ScrollName As ScrollView, PanelName As Panel, Values() As String, ColumnWidth() As Int)
Dim col As Int
Header.Initialize("")
For col = 0 To Values.Length - 1
Dim lbl As Label
lbl.Initialize("")
lbl.Text = Values(col)
lbl.Gravity = Gravity.CENTER
lbl.TextSize = FontSize
lbl.Color = HeaderColor
lbl.TextColor = HeaderFontColor
lbl.Tag = col
Header.AddView(lbl, GetColLeft(ColumnWidth, col), 0, ColumnWidth(col) - ColLineBorder, RowHeight)
Next
PanelName.AddView(Header, ScrollName.Left, ScrollName.Top - (RowHeight + RowLineBorder), ScrollName.Width, RowHeight + RowLineBorder)
End Sub

Sub GetColLeft(ColumnWidth() As Int, ColNum As Int) As Int
Dim i, ColWidth As Int
ColWidth = 0
For i = 0 To ColNum - 1
ColWidth = ColWidth + ColumnWidth(i)
Next
Return ColWidth
End Sub
 
Upvote 0

Massimiliano

Member
Licensed User
Longtime User
Yes I know it works, but if change the manifest file version as follow
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19"/>
instead of
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="14"/>

and then

SetApplicationAttribute(android:hardwareAccelerated, "false")

No longer works for me (Motorola motog lte xt1039 - android 4.4.4)
 
Upvote 0
Top