B4J Question How to change CheckBox value in a CLV

Hi!

I try to activate or deactivate all the checkboxes that are in a CLV.

Checks also have a function in the _CHECK activity

B4X:
Sub CHECK_CheckedChange(Checked As Boolean)
    Dim index As Int = lstRutes.GetItemFromView(Sender)
    Dim pnl As B4XView = lstRutes.GetPanel(index)
    Dim chk As B4XView = pnl.GetView(0)

    Sleep(100)
    
    If chk.Checked = True Then
        MU.SelectUser(chk.Text)
    Else If chk.Checked = False Then
        For i = MU.SelectedUsers.Size-1 To 0 Step -1
            Dim temp_user As UserInfo : temp_user.initialize : temp_user = MU.SelectedUsers.get(i)
            If temp_user.Rute = chk.Text Then
                MU.SelectedUsers.RemoveAt(i)
                Log("Ruta quitada de la lista : " & chk.Text)
            End If
        Next
    End If
    
    Sleep(10)
    getMBrands
    getMProducts
    getMProviders
End Sub

The first time it works, but when I try to change them again nothing happens, I don't even get an error message. Use logs to see the process but it does not show anything, it is as if the function will not execute.



This is the function i use to change the Checks Values:

B4X:
Private Sub btnSelectAll_Click
    Dim v As Boolean
    
    If btnSelectAll.Text = "Seleccionar todos" Then
         v = True
         btnSelectAll.Text = "Deseleccionar todos"
    Else
        v = False
        btnSelectAll.Text = "Seleccionar todos"
    End If
    
    For i =0 To lstRutes.Size -1
        Dim pnl As B4XView = lstRutes.GetPanel(i)
        Dim checkbox As B4XView = pnl.GetView(0)
        
        If v = True Then MU.SelectUser(checkbox.Text)
        If v = False Then MU.unSelectUser(checkbox.Text)
        checkbox.Checked = v
    Next
    
End Sub
 

Erel

Administrator
Staff member
Licensed User
Bad:
B4X:
Dim temp_user As UserInfo : temp_user.initialize : temp_user = MU.SelectedUsers.get(i)
Good:
B4X:
Dim temp_user As UserInfo = MU.SelectedUsers.get(i)

1. Remove the Sleep calls.
2. Add Log("CHECK_CheckedChange") in that sub. If I remember correctly, it will be called when you programmatically set the Checked property.
 
Upvote 0
Top