B4J Question [Solved]How Change Tableview Columns Runtime ??

behnam_tr

Active Member
Licensed User
Longtime User
hello everyone

I need to change Tableview Columns Header and width runtime

I have a problem with the Tableview
When I change the Columns Header and and their width , the format of the previous Columns and their size remain.

sample attached.

 

Attachments

  • tableview_col.zip
    2.8 KB · Views: 222
Solution
Removing and recreating the table is not very efficient or standard.
HERE is a solution:
The problem is caused when you use JavaObject to set the row height.
Follow these steps:
First, remove this line from your code:
B4X:
    asJO(tb).RunMethod("setFixedCellSize",Array(rowsize))    'Remove it. It causes the problem.
Second, to adjust the 'cellsize', use css:
1. Create a css.txt file in your assets folder and add it to the project. In the css.txt file, put this: (assuming you want 36 to be the fixedcellsize)
.table-view .cell { -fx-cell-size: 36; -fx-padding: 0px; }
2. Add this line after MainForm.Show:
B4X:
    MainForm.Stylesheets.Add(File.GetUri(File.DirAssets, "css.txt"))

This way you can set the cell heights without...

DonManfred

Expert
Licensed User
Longtime User
what about creating another initialisation method?

B4X:
Sub NewLayout
    
    Dim hl As List = Array As String("col1","col2","col3")
    TableView1.SetColumns(hl)
    Dim columnWidth() As Int = Array As Int(50,260,65) ' set the new comlumnsizes here
    Dim Right_Align() As Int = Array As Int(1)
    Dim Left_Align() As Int = Array As Int()
    Dim RowHeight As Double = 36.0
    Dim single_selection As Boolean = False
    Dim sorting As Boolean =False
    Prepare_Tableview(TableView1,columnWidth,single_selection,RowHeight,Right_Align,Left_Align,sorting)
    
    
End Sub
 
Upvote 0

behnam_tr

Active Member
Licensed User
Longtime User

I added through Designer
I do the size exactly according to the above code, but the result is the same
It should be a way to clear the size of the previous columns
I added it through coding, but the result was the same as before
 
Upvote 0

behnam_tr

Active Member
Licensed User
Longtime User
This is the only solution I found
Is this a standard solution ??

B4X:
Sub New_Layout
    
    Dim l As Int = TableView1.Left
    Dim t As Int = TableView1.Top
    Dim w As Int = TableView1.Width
    Dim h As Int = TableView1.Height
    
    TableView1.RemoveNodeFromParent
    
    Dim TableView1 As TableView
    TableView1.Initialize("TableView1")
    MainForm.RootPane.AddNode(TableView1,l,t,w,h)
    
    Dim hl As List = Array As String("col111","col222","col333")
    TableView1.SetColumns(hl)
    Dim columnWidth() As Int = Array As Int(100,200,90)
    Dim Right_Align() As Int = Array As Int(1)
    Dim Left_Align() As Int = Array As Int()
    Dim RowHeight As Double = 36.0
    Dim single_selection As Boolean = False
    Dim sorting As Boolean =False
    Prepare_Tableview(TableView1,columnWidth,single_selection,RowHeight,Right_Align,Left_Align,sorting)
    
    
End Sub
 
Upvote 0

MegatenFreak

Active Member
Licensed User
Removing and recreating the table is not very efficient or standard.
HERE is a solution:
The problem is caused when you use JavaObject to set the row height.
Follow these steps:
First, remove this line from your code:
B4X:
    asJO(tb).RunMethod("setFixedCellSize",Array(rowsize))    'Remove it. It causes the problem.
Second, to adjust the 'cellsize', use css:
1. Create a css.txt file in your assets folder and add it to the project. In the css.txt file, put this: (assuming you want 36 to be the fixedcellsize)
.table-view .cell { -fx-cell-size: 36; -fx-padding: 0px; }
2. Add this line after MainForm.Show:
B4X:
    MainForm.Stylesheets.Add(File.GetUri(File.DirAssets, "css.txt"))

This way you can set the cell heights without causing the weird problem.
Hope this helps
 
Upvote 1
Solution
Cookies are required to use this site. You must accept them to continue using the site. Learn more…