B4J Question Tableview - save & set column widths for next session

Mark Stuart

Well-Known Member
Licensed User
Longtime User
Howdy folks,

I would like to allow the user to adjust the Tableview column widths as they want.
When the app closes, save the column widths to the KeyValueStore (kvs).
In AppStart, restore the column widths and set them from the stored values.

I'm able to write and read the column widths correctly, but after the MainForm.Show, the columns are at default width again.
What do I need to do to get this to work?

Restore and Save calls:
AppStart:
Utils.RestoreTableWidths("Customers",tvCustomers)

MainForm_CloseRequest:
Utils.SaveTableWidths("Customers",tvCustomers)

The Utils functions to Restore and Save:

B4X:
Sub RestoreTableWidths(Key As String, tv As TableView)
    If kvs.ContainsKey(Key) = False Then Return

    Dim lst As List = kvs.Get(Key)

    For i = 0 To lst.Size - 1
        Dim w As Double = lst.Get(i)
        tv.SetColumnWidth(i,w)
    Next
End Sub

B4X:
Sub SaveTableWidths(Key As String, tv As TableView)
    Dim lst As List
    lst.Initialize
    
    For i = 0 To tv.ColumnsCount - 1
        Dim colWidth As Double = tv.GetColumnWidth(i)
        lst.Add(colWidth)
    Next

    kvs.Put(Key, lst)
End Sub
 
Top