1.You create a B4xtable using sorting mode it will add complexity to caculate item location. for each click you do dataupdated, actived visible items location will be changed, perhaps they will be invisible if you are on next page.
2. It is wrong way to you use rowid to SetRowColor, for firstpage it works , but when next page, the rowid will be out of visbleRowIds range.
1.You create a B4xtable using sorting mode it will add complexity to caculate item location. for each click you do dataupdated, actived visible items location will be changed, perhaps they will be invisible if you are on next page.
I took away the auto-sort functionality, and it seemed to work fine (for the first page, at least... didn't test other pages). However, that defeats the purpose of the B4XTable (in this case). The active items need to be sorted to the top.
Would it be possible to use a manual sort and not have the strange behavior?
No, I meant actived items positon will change. for example, current page is 3, when you activate a certain item, because of sorting ,it might be at page 1, it will be invisible.
I took away the auto-sort functionality, and it seemed to work fine (for the first page, at least... didn't test other pages). However, that defeats the purpose of the B4XTable (in this case). The active items need to be sorted to the top.
Do you consider the case of multiple page, when the active items be sorted to the top and it is not in currentpage how you process ? the issue is same as 1.
...actived items positon will change. for example, current page is 3, when you activate a certain item, because of sorting ,it might be at page 1, it will be invisible.
Yes, this is expected and desired behavior. All activated items will be moved to the beginning of the list, and there could be multiple pages of activated items.
What was not expected was that just because the table is sorted that the "VisibleRows" is not always [0,1,2,...n] where n is the last visible row on the current page!
I didn't expect to have to do anything special to keep my list ordered and rows selected. The table has a list of rows, and it knows which rows are being viewed at any one time. So, whenever I click a row, it should just be pointing to that row.
Do you consider the case of multiple page, when the active items be sorted to the top and it is not in currentpage how you process ? the issue is same as 1.
I don't see how that's a problem. I might switch to using a single xCustomListView and trying to work it like I'm trying to work the B4XTable. Although, with the B4XTable, I guess I can sort my rows and redo the SetData(). That just seems very smelly.
Try the B4J or B4A project modified attached. I removed the B4XSelections code and module which was interfering and changed a few things in the code. It worked for me after I made the changes when I tested in B4J and B4A, provided I understood your question.
Try the B4J or B4A project modified attached. I removed the B4XSelections code and module which was interfering and changed a few things in the code. It worked for me after I made the changes when I tested in B4J and B4A, provided I understood your question.
Ah, thank you! That helped. I went in and made one more adjustment to your code, and now it works exactly as I want! I can activate and deactivate rows, plus I can select (and highlight) rows as well!
I tried my fix with my original code, but the B4XTableSelections still messes up, even though I can get a highlighted row. I think it is a simple bug in B4XTableSelections. I suspect it can be fixed to work properly. I will investigate further when I get a chance, but if anyone wants to beat me to it, have at it!
The new code, that makes row selection possible, is this:
How To Highlight Selected Row When B4XTable Sorted:
Private Sub tbl_Items_CellClicked (ColumnId As String, RowId As Long)
tbl_Items_SetRowColors
tbl_Items_SetSelectedRowColor(RowId)
End Sub
Sub tbl_Items_SetSelectedRowColor(SelRowId As Long)
For i = 0 To tbl_Items.VisibleRowIds.Size - 1
Dim RowId As Long = tbl_Items.VisibleRowIds.Get(i)
If RowId = SelRowId Then
SetRowColor(i, xui.Color_Yellow)
End If
Next
End Sub
That seems to be the "fix" to the unexpected behavior of the original code, where clicking on a row did not necessarily mean that particular RowId was the actual RowId clicked.
I can obviously just pass the RowId to tbl_Items_SetRowColors() and only have one sub, but this is the way it's posted for now... ?