Greenletuce
Member
Hi everyone, this is my first post on the forum, I am still a newbie to b4x programming and I know my questions might be silly but I have been looking for the solution to my problem in the numerous b4a and b4x guides, searching the forum but I haven't quite found a proper answer to my question.
Here is what I'm trying to achieve : I have 27 items represented as checkboxes, all loaded in the Designer and I want the user to select only 7 of them. When he reaches this limit he cannot check further boxes, the user gets a toast message saying he can only select 7 checkboxes and he must first uncheck the previously selected boxes in order to select other boxes until reaching again the limit of 7 and so on.
So I proceeded like this : I changed the event name of all my 27 checkboxes into "chk" and created a sub called chk_CheckedChange. In this sub I created a "virtual" checkbox so every time a checkbox is checked, the number of selected checkboxes increases until reaching the limit of 7. Here is my code :
And what it does is, I can check my checkboxes until I reach the limit of 7, then I receive the toast message, but I cannot check other checkboxes even after i uncheck the previous ones.
As I said, I've tried to find a solution on the forum without success, so I tried figuring it out myself but I cannot understand where the problem is. I think it's just a simple element I didn't add but I can't quite find what it is. Thank you in advance.
Here is what I'm trying to achieve : I have 27 items represented as checkboxes, all loaded in the Designer and I want the user to select only 7 of them. When he reaches this limit he cannot check further boxes, the user gets a toast message saying he can only select 7 checkboxes and he must first uncheck the previously selected boxes in order to select other boxes until reaching again the limit of 7 and so on.
So I proceeded like this : I changed the event name of all my 27 checkboxes into "chk" and created a sub called chk_CheckedChange. In this sub I created a "virtual" checkbox so every time a checkbox is checked, the number of selected checkboxes increases until reaching the limit of 7. Here is my code :
B4X:
Sub chk_CheckedChange(Checked As Boolean)
Dim virtual_chk As CheckBox
Log(nbr_chk_selected)
virtual_chk = Sender
If virtual_chk.Checked = True And nbr_chk_selected >= 7 Then
virtual_chk.Checked = False
ToastMessageShow("You cannot select more than 7 checkboxes.", False)
Else
End If
If virtual_chk.Checked Then
nbr_chk_selected = nbr_chk_selected + 1
Else
End If
End Sub
And what it does is, I can check my checkboxes until I reach the limit of 7, then I receive the toast message, but I cannot check other checkboxes even after i uncheck the previous ones.
As I said, I've tried to find a solution on the forum without success, so I tried figuring it out myself but I cannot understand where the problem is. I think it's just a simple element I didn't add but I can't quite find what it is. Thank you in advance.