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
 

klaus

Expert
Licensed User
Longtime User
Attached you have a modified version of the TableExample program with row and column lines.
The line color is the ScrollView.Panel.Color.
So the row and column line colors are the same.
The line width can be set in the ColLineWidth and RowLineWidth variables.
The lines are generated by shifting the lables by the line width. That means that the Label.Width is equal to the column width minus the line width and the same for the height.

Best regards.
 

Attachments

  • TableExample.jpg
    TableExample.jpg
    41.6 KB · Views: 35,630
  • TableExample1.jpg
    TableExample1.jpg
    39.2 KB · Views: 3,375
  • TableExample2.jpg
    TableExample2.jpg
    34.4 KB · Views: 3,268
  • TableExample1.2.zip
    12.3 KB · Views: 6,490
Last edited:
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
Attached you have a modified version of the TableExample program with row and column lines.
The line color is the ScrollView.Panel.Color.
So the row and column line colors are the same.
The line width can be set in the ColLineWidth and RowLineWidth variables.
The lines are generated by shifting the lables by the line width. That means that the Label.Width is equal to the column width minus the line width and the same for the height.

Best regards.

Ok, time for me to give this a go. I need to create multiple tables on different activity screens (only ever one per screen). Had a look at the code and think I can figure out the usage. My question is, can most of this code by added to a code module and called. Would it just be a matter of adding all but the process globals and activity_create to the code module (called 'table' for now) and then calling table.LoadTableFomCSV(File.DirAssets, CSVListName.csv, true).

Hope this can be done as it will mean I wont have to add all the subs to each activity I need a table on. Thanks.
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
This will probably be fround upon, but I could do with knowing if this is possible so...... bump
 
Upvote 0

magarcan

Active Member
Licensed User
Longtime User
I'm working over example v1.2, but I have some problems:
  1. How can I change of each one of the columns?
  2. Can I show images or links inside grid?
  3. I'm using Latin characters inside de CSV file, but they aren't showed well.
  4. How can I convert code to a module?

Thanks!
 
Last edited:
Upvote 0

magarcan

Active Member
Licensed User
Longtime User
I'm working over example v1.2, but I have some problems:
  1. How can I change of each one of the columns?
  2. Can I show images or links inside grid?
  3. I'm using Latin characters inside de CSV file, but they aren't showed well.
  4. How can I convert code to a module?

Thanks!
An other question. Can I set up different actions for different cells??
Thanks!!
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
You could have a look at this thread where you find lots of ScrollView examples.
1) Have a look at this example ScrollView example with multiselection and SQL
2) Images yes. Links, I have never tried it but should be possible.
3) You should save your csv file with UTF-8 encoding.
Otherwise you could use TextReader with ISO-8859-1 encoding, but you must read each line and separate the entries yourself.
4) You can only do it in a Code Module. You should try doing it.

Best regards.
 
Upvote 0

cbal03

Member
Licensed User
Longtime User
Great examples and thorough explanations!

Hello Klaus,
Just wanted to say thank you.

The cell dividing lines give a very clean look too!

:sign0087:
 
Upvote 0

Kristofferson

New Member
Licensed User
Longtime User
Sorting

Hi, i'm a new member of this forum. I recently purchased B4A and i'm having a great time using it. :)
I've been reading the forum and found so many helpful tips. Then i stumbled with this thread which is what i need.

I do have a question. Is column sorting possible for this TableView?

I'm looking into sorting the CSV data first before loading in the TableView but not sure if will be is faster/efficient as it will need to clear and reload all csv data.

Can you provide a better solution for this?

Thanks!

:sign0163:
 
Upvote 0

nemethv

Member
Licensed User
Longtime User
Hi,

I'm trying to get to define the colour of the cell based on the content of another cell in the same row.

This is the code as it was in the SQL tutorial, exc for one line that I added:
B4X:
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

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)
      If i = 0 AND GetView(rc.Row,1).Text = "Something" Then L.Color = Colors.Red 
'this is what I added. Basically, for Col0 only, if the cell after (same row, Col1) says "something", 
'I want Col0's cell to be red for that line, otherwise stay as predefined. However when I use this 
'construct, it tells me View should be initialised first. And I'm not too sure it will work anyway.
   Next
   
   NumberOfRows=NumberOfRows+1
   Table.Height = NumberOfRows * RowHeight
End Sub
Thanks!
 
Upvote 0

mc73

Well-Known 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:
B4X:
For i = numberOfColumns-1 To 0 step -1
and then avoid the subroutine, by changing line
B4X:
 If i = 0 AND GetView(rc.Row,1).Text = "Something" Then L.Color = Colors.Red
to
B4X:
If i = 0 AND Table.GetView(rc.Row * NumberOfColumns + 1).Text = "Something" Then L.Color = Colors.Red
and placing it above line
B4X:
Table.AddView(L, ColWidth, RowHeight * NumberOfRows, ColumnWidth_1(i), RowHeight_1)
 
Upvote 0
Top