B4J Question Activating Multiple Rows in B4XTable

B4XDev

Member
Licensed User
In a follow up to this thread, I switched to a B4XTable solution (attached).

I can activate/deactivate rows, and those activated rows show at the top of the list. This is desired behavior.

However, once a row (item) has been activated, left-clicking a table row is messed up.

If you are able, please help me understand and/or fix this glitch. Thank you!

2023.01.10 Update - Thanks to @Mahares , looks like we've got it working! See attached project.
 

Attachments

  • B4XTableActivateRowsMahares-WithRowSelect.zip
    21.1 KB · Views: 80
Last edited:

teddybear

Well-Known Member
Licensed User

I read your code quickly.

There are 2 issues:

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.
 
Last edited:
Upvote 0

B4XDev

Member
Licensed User
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.

Are you saying visible items might not actually be visible?

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.

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?
 
Upvote 0

teddybear

Well-Known Member
Licensed User
Are you saying visible items might not actually be visible?
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.
Would it be possible to use a manual sort and not have the strange behavior?
It depends on your sorting requirements
 
Upvote 0

B4XDev

Member
Licensed User
...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.

It depends on your sorting requirements

Just want to sort by the active column and then the item column.
 
Upvote 0

teddybear

Well-Known Member
Licensed User
Just want to sort by the active column and then the item column.
It will be a problem in multi-page. when there are many active items in multi-pages, which page is you want to show after each clicking?
 
Upvote 0

B4XDev

Member
Licensed User
It will be a problem in multi-page. when there are many active items in multi-pages, which page is you want to show after each clicking?

It should remain on the same page any time a row is clicked, even if that row "disappears" and goes to the first page.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
However, once a row (item) has been activated, left-clicking a table row is messed up.
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.
 

Attachments

  • B4XTableActivateRowsMahares.zip
    21.1 KB · Views: 80
Upvote 0

B4XDev

Member
Licensed User

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!

I will post the fixed code in the original post.
 
Upvote 0

B4XDev

Member
Licensed User
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... ?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…