Android Question Get checked rows in B4Xtable

Mostez

Well-Known Member
Licensed User
Longtime User
based on Erel's example, i added checkbox to B4Xtable column and name it 'Select' now i want to iterate thru table rows to get checked-only rows. how to do this?

B4X: Copy
tblPhoneContacts.Clear
CheckColumn = tblPhoneContacts.AddColumn("Select", tblPhoneContacts.COLUMN_TYPE_TEXT)
CheckColumn.Width = 60dip
CheckColumn.Searchable = False
CheckColumn.Sortable = False

B4X: Copy
For i = 1 To CheckColumn.CellsLayouts.Size - 1 'add custom check box to table
    'Sleep(0)
    Dim pnl As B4XView = CheckColumn.CellsLayouts.Get(i)
    Dim ColCheckBox As CheckBox
    ColCheckBox.Initialize("")
    St.SetButtonTintList(ColCheckBox,Colors.Gray,SysDeclare.COLOR_DARK_NAVY)
    pnl.AddView(ColCheckBox, 5dip, 5dip, CheckColumn.Width - 10dip, tblPhoneContacts.RowHeight - 10dip)
Next
 
now i want to iterate thru table rows to get checked-only rows
Maybe something like this:
Code: Copy
Sub btn_Click
    For i = 0 To B4XTable1.VisibleRowIds.Size - 1
        Dim RowId As Long = B4XTable1.VisibleRowIds.Get(i)
        Dim pnl As B4XView = CheckColumn.CellsLayouts.Get(i + 1) '+1 because first cell is a header
        Dim ColCheckBox As CheckBox    = pnl.GetView(1)
        If RowId > 0 Then
            Dim row As Map = B4XTable1.GetRow(RowId)
            If ColCheckBox.Checked Then
                Log($"Checked rowid ${RowId} "$)    
'                Log($"rowid ${RowId}   ${row.Get("Name")}"$)  'Name is header of another column to display  
            End If
        End If
    Next    
End Sub
 
Upvote 0
Dim row As Map = B4XTable1.GetRow(RowId)
Hi @Mostez: If you uncomment the line I have commented in the code, the line will be used. If you have another column named Name for example, it will show you the content of each based on the rowid. You can use another col name if you want.
 
Upvote 0
i tried both methods, Erel's method is much simpler to implement, now I need to iterate thru table to get selected rows, how to do that?
thanks
 
Upvote 0
Erel's method is much simpler to implement, now I need to iterate thru table to get selected rows
To iterate thru the table to get selected rows, you need to use: XSelections.SelectedLines.Keys
Code: Copy
For Each rowid As Long In XSelections.SelectedLines.Keys
   'your code here. If you have trouble, post your code. Someone may be able to help.
Next
 
Upvote 0
big thanks, it worked without problems, so far :)
B4X: Copy
For Each rowid As Long In TableStyle.SelectedLines.Keys
                Dim row As Map = tblPhoneContacts.GetRow(rowid)
                    Cont.CompanyName =     row.Get("CompanyName")
                    Cont.ContactName = row.Get("ContactName")
                   ...

            Next
 
Upvote 0
Back
Top