merging table cells

noclass1980

Active Member
Licensed User
Longtime User
I've created a table using Erel's tableview class (thanks!) but would like to merge two cells in the header row so they are centred over two columns. Eg in the header row, cols 2 and 3 appear to be just one cell with the text centred over the data in cols 2 and 3 in rows 0, 1, 2 etc. This is the same as the merge function in excel. Any suggestions? Thanks
 

mangojack

Expert
Licensed User
Longtime User
Unless you receive a more efficient method , a simplistic way would be to position a label over the columns.

B4X:
Sub Activity_Create(FirstTime As Boolean)
      
   Table1.Initialize(Me, "Table1", 4)
   Table1.AddToActivity(Activity, 0, 0dip, 100%x, 50%y)   
   Table1.SetHeader(Array As String("Col0", "", "", "Col3"))  ' Empty header values Col2 and Col3
    For i = 0 To 5000
      Table1.AddRow(Array As String("Row: " & i, "ccc", "ddd", "eee"))
   Next
   Table1.SetColumnsWidths(Array As Int(100dip, 30dip, 130dip, 100%x - 260dip))
   
   'Place label over columns 2 and 3
   Dim  Label1 As Label
   Label1.Initialize("")  
   Activity.AddView(Label1,101dip,0dip,160dip,Table1.RowHeight)
   Label1.Text = "My Header Value"
   Label1.TextColor = Table1.HeaderFontColor
   Label1.TextSize = Table1.FontSize
   Label1.Color = Table1.HeaderColor
   Label1.Gravity = Gravity.CENTER

The underlying table headers still fire the click event for both cols,so watch that if you are using the click event and you use this workaround.

Cheers
 
Upvote 0

noclass1980

Active Member
Licensed User
Longtime User
Thanks for the reply, I had though of using simple labels but just wondered if there was a way to merge. I can use the label approach in any case.

Cheers

Unless you receive a more efficient method , a simplistic way would be to position a label over the columns.

B4X:
Sub Activity_Create(FirstTime As Boolean)
      
   Table1.Initialize(Me, "Table1", 4)
   Table1.AddToActivity(Activity, 0, 0dip, 100%x, 50%y)   
   Table1.SetHeader(Array As String("Col0", "", "", "Col3"))  ' Empty header values Col2 and Col3
    For i = 0 To 5000
      Table1.AddRow(Array As String("Row: " & i, "ccc", "ddd", "eee"))
   Next
   Table1.SetColumnsWidths(Array As Int(100dip, 30dip, 130dip, 100%x - 260dip))
   
   'Place label over columns 2 and 3
   Dim  Label1 As Label
   Label1.Initialize("")  
   Activity.AddView(Label1,101dip,0dip,160dip,Table1.RowHeight)
   Label1.Text = "My Header Value"
   Label1.TextColor = Table1.HeaderFontColor
   Label1.TextSize = Table1.FontSize
   Label1.Color = Table1.HeaderColor
   Label1.Gravity = Gravity.CENTER

The underlying table headers still fire the click event for both cols,so watch that if you are using the click event and you use this workaround.

Cheers
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
Erel , changing column widths affects the entire table , including field headers, no ?.
I'm sure he wants one less column, in the header row ( one header field covering two data columns). The only other alternative I could come up with was a separate table for header and data.

Cheers mj
 
Last edited:
Upvote 0
Top