B4J Question B4XTable FrozenColumns at right?

PaulMeuris

Well-Known Member
Licensed User
I added a column in the main module and adjusted the Main_Resize subroutine:
B4X:
    Private MyColumn As B4XTableColumn

    B4XTable1.NumberOfFrozenColumns = 2
    MyColumn = B4XTable1.AddColumn("Mycol", B4XTable1.COLUMN_TYPE_VOID)
    MyColumn.Width = 130dip
   
    Public Sub Main_Resize
    ' reposition the Edit column
    B4XTable1.GetColumn("Edit").Panel.Left = B4XTable1.clvData.AsView.Left + B4XTable1.clvData.AsView.Width
    B4XTable1.GetColumn("Mycol").Panel.Left = B4XTable1.clvData.AsView.Left + B4XTable1.clvData.AsView.Width + B4XTable1.GetColumn("Edit").Panel.Width
    ' adjust width of the last column when resizing to the right
    ' -3 => column1 removed, edit column, index start at 0
    B4XTable1.clvData.ResizeItem(B4XTable1.Columns.Size-4, B4XTable1.GetColumn("Column A").Panel.Width)
    B4XTable1.clvData.ResizeItem(B4XTable1.Columns.Size-5, B4XTable1.GetColumn("Column A").Panel.Width)
End Sub
And of course if you add more than 1 extra column you will have to adjust the Main_Resize subroutine again.
I did not change the B4XTable class.
Does this suit your needs?
Happy coding!
 
Last edited:
Upvote 0

aeric

Expert
Licensed User
Longtime User
Sorry to bother you so much, Paul.

As I made more tests, I found some minor bugs.

1. If I resize the form wider, there is a small gap before the frozen columns.
1678097130835.png


2. If I preset the column width, there are gaps between the unfreeze columns.
1678097224636.png


By the way, I probably would only use 1 frozen column on the right.
However, I hope this feature is working fine in the future for the sake of other members. I understand it would take a lot of time to fix the bugs.
So for the time being, I will use the workaround as posted above.
Thanks Paul and others.
 

Attachments

  • FrozenColumnsDemo2.zip
    13 KB · Views: 133
Upvote 0

PaulMeuris

Well-Known Member
Licensed User
The resize subroutine works because the B4XTable view is anchored in the layout.
And if you don't use fixed column widths then the B4XTable class takes care of the recalculating of the column widths.
So this code also works:
B4X:
'    Column1.Width = 150dip
'    Column2.Width = 180dip
'    Column3.Width = 160dip
'    Column4.Width = 200dip
'    Column5.Width = 180dip
'    Column6.Width = 160dip

Public Sub Main_Resize
    B4XTable1.GetColumn("Column E").Panel.Left = B4XTable1.clvData.AsView.Left + B4XTable1.clvData.AsView.Width
    B4XTable1.GetColumn("Edit").Panel.Left = B4XTable1.clvData.AsView.Left + B4XTable1.clvData.AsView.Width + B4XTable1.GetColumn("Column E").Panel.Width
    '
    B4XTable1.clvData.ResizeItem(B4XTable1.Columns.Size-4, B4XTable1.GetColumn("Column A").Panel.Width)
    B4XTable1.clvData.ResizeItem(B4XTable1.Columns.Size-5, B4XTable1.GetColumn("Column A").Panel.Width)

'    B4XTable1.clvData.ResizeItem(0, B4XTable1.GetColumn("Column A").Panel.Width)
'    B4XTable1.clvData.ResizeItem(1, B4XTable1.GetColumn("Column B").Panel.Width)
'    B4XTable1.clvData.ResizeItem(2, B4XTable1.GetColumn("Column C").Panel.Width)
'    B4XTable1.clvData.ResizeItem(3, B4XTable1.GetColumn("Column D").Panel.Width)
End Sub
Notice that the Column E resizes together with the previous columns. The Edit column however has a fixed column width and that doesn't change.
I didn't get it to work with the fixed column widths.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I probably would only use 1 frozen column on the right
Attached is a fully revised version of your project in post #22 where the original internal B4XTable library was used rather than a modified class. No modifications to the library were made. The project uses 2 B4XTables side by side to synchronize the movement. The table on the right contains the Edit column views only which is always anchored to the right. No stray gaps between columns. I tested it extensively. It worked well for me. I hope it does for you when you test it.

1678279648415.png
 

Attachments

  • FrozenColumnsSyncTwoTablesMaharesForForum.zip
    3.5 KB · Views: 113
Upvote 0
Top