noticed that the tableview is not refreshed automatically after changing data.
Question: It would require a routine like I made below OR is there a tv.Refresh routinr?
B4X:
' To refresh the tableview (id: tableviewStandard) displayed data with any new data
Sub tableviewStandard_Refresh
' Get the selected row
Dim rs As Int = tableviewStandard.SelectedRow
' Use a temporary list which holds the updated row (cells) objects as taken from the updated tableview list
Dim tvl As List
tvl.Initialize
tvl.AddAll(tableviewStandard.Items)
' Clear all items in the tableview list
tableviewStandard.Items.Clear
' And add the objects from the list to the tableviewStandard items
For i = 0 To tvl.Size - 1
Dim r() As Object = tvl.Get(i)
tableviewStandard.Items.Add(Array As Object(r(0), r(1)))
Next
' Set the selected row
tableviewStandard.SelectedRow = rs
End Sub
Hi!
Thanks for both replies I managed Erel solution but could not get it to change the table...now i know because it does not refresh. I cannot see any refresh, maybe Erel will help.
Thanks Dave.
Hi!
Erel your solution works OK but my table has about 12 columns and all may need editing, yours only used 1 column, I could not work out how to put labels in all 'cells'.
rwblinn, your solution is the easiest but the table does not refresh, the item list contains the new data but no refresh.
I am still continuing with both options. Thanks again Dave.
It should be simple to make all the values Labels.
This sub will add a row of strings to the table as a row of labels:
B4X:
Sub AddRow(tv As TableView, Row() As String)
Dim rowOfLabels(Row.Length) As Object
For i = 0 To Row.Length - 1
Dim lbl As Label
lbl.Initialize
lbl.Text = Row(i)
rowOfLabels(i) = lbl
Next
tv.Items.Add(rowOfLabels)
End Sub
Now all you need to do when editing an item, is to get the Row of objects, convert the correct one to Label and change its text.
Hi Erel!
Thanks for the sample code it worked ok however it caused problems further down the code, but it has great potential for other projects.
So I used your first suggestion and managed to force the tableview to refresh I used this:-
Sub tableRefresh
Table1 .SetColumnVisible (0,False) 'Forces a table refresh
Table1 .SetColumnVisible (0,True)
End Sub
it might not be the correct way but it works and is only 2 lines.
Thanks for all your help on this problem but'I'll be back'
Dave.
This method doesn't work if you use TextField in the rows of the TableView. :-(
[EDIT]
The only method I found to refresh the tableView with Textfield is using a timer.
B4X:
Sub Process_Globals
Private tv1 As TableView
Private TimerRefresh As Timer
End Sub
Sub AppStart (Form1 As Form, Args() As String)
TimerRefresh.Initialize("TimerRefresh", 1)
End Sub
Sub tv1StartRefresh
For i = 0 To tv1.ColumnsCount -1
tv1.SetColumnVisible(i, False)
Next
TimerRefresh.Enabled = True
End Sub
Sub TimerRefresh_Tick
For i = 0 To tv1.ColumnsCount -1
tv1.SetColumnVisible(i, True)
Next
TimerRefresh.Enabled = False
End Sub
Because hiding/showing the column in the same sub doesn't work. B4J is missing a "DoEvent" like in B4A. The problem here is that there is an ugly 1ms moment where the columns are hidden....