T trueboss323 Active Member Licensed User Longtime User Aug 12, 2018 #1 Hello, I have a CustomListView and each line I have in the list has a checkbox that corrisponds to a setting. I use Statemanager to check if it’s true or false , then check/uncheck the box and move on to the next. So instead of doing something like: Code: Copy If Statemanger.Getsetting(“key1”) = True Then Checkbox1.checked = True Else Checkbox1.checked = False End if If Statemanger.Getsetting(“key2”) = True Then Checkbox2.checked = True Else Checkbox2.checked = False End if If Statemanger.Getsetting(“key3”) = True Then Checkbox3.checked = True Else Checkbox3.checked = False End if Can the whole thing be done in a loop instead? Something like: Code: Copy For Each chk as Checkbox in CustomListView
Hello, I have a CustomListView and each line I have in the list has a checkbox that corrisponds to a setting. I use Statemanager to check if it’s true or false , then check/uncheck the box and move on to the next. So instead of doing something like: Code: Copy If Statemanger.Getsetting(“key1”) = True Then Checkbox1.checked = True Else Checkbox1.checked = False End if If Statemanger.Getsetting(“key2”) = True Then Checkbox2.checked = True Else Checkbox2.checked = False End if If Statemanger.Getsetting(“key3”) = True Then Checkbox3.checked = True Else Checkbox3.checked = False End if Can the whole thing be done in a loop instead? Something like: Code: Copy For Each chk as Checkbox in CustomListView
stevel05 Expert Licensed User Longtime User Aug 12, 2018 #2 If you add all of the checkboxes to a list or Array, you can iterate of the collection. Something like: Code: Copy Dim Checkboxes As List = Array(CheckBox1,Checkbox2,Checkbox3) 'etc. For Each CB as Checkbox in Checkboxes ... do whatever Next Upvote 0
If you add all of the checkboxes to a list or Array, you can iterate of the collection. Something like: Code: Copy Dim Checkboxes As List = Array(CheckBox1,Checkbox2,Checkbox3) 'etc. For Each CB as Checkbox in Checkboxes ... do whatever Next
T trueboss323 Active Member Licensed User Longtime User Aug 12, 2018 #3 stevel05 said: If you add all of the checkboxes to a list or Array, you can iterate of the collection. Something like: Code: Copy Dim Checkboxes As List = Array(CheckBox1,Checkbox2,Checkbox3) 'etc. For Each CB as Checkbox in Checkboxes ... do whatever Next Click to expand... This solves half of my problem , but how do I do it when I want to check for each specific setting? It’s not as simple as checking all the boxes at once but rather based on the Statemanger setting. Upvote 0
stevel05 said: If you add all of the checkboxes to a list or Array, you can iterate of the collection. Something like: Code: Copy Dim Checkboxes As List = Array(CheckBox1,Checkbox2,Checkbox3) 'etc. For Each CB as Checkbox in Checkboxes ... do whatever Next Click to expand... This solves half of my problem , but how do I do it when I want to check for each specific setting? It’s not as simple as checking all the boxes at once but rather based on the Statemanger setting.
Erel B4X founder Staff member Licensed User Longtime User Aug 12, 2018 #4 Tip: Code: Copy If Statemanger.Getsetting(“key1”) = True Then Checkbox1.checked = True Else Checkbox1.checked = False End if Equivalent to: Code: Copy Checkbox1.Checked = Statemanger.Getsetting(“key1”) = True You don't need to have references to all checkboxes. It is difficult to post a solution without seeing your layout however if all items are built with the same layout then it is very simple to set the Checkboxes. For example to set Checkbox of item #2: Code: Copy 'assuming that the checkbox index is 1 in the layout. clv.GetPanel(3).GetView(1).Checked = Statemanger.Getsetting(“key2”) = True Upvote 0
Tip: Code: Copy If Statemanger.Getsetting(“key1”) = True Then Checkbox1.checked = True Else Checkbox1.checked = False End if Equivalent to: Code: Copy Checkbox1.Checked = Statemanger.Getsetting(“key1”) = True You don't need to have references to all checkboxes. It is difficult to post a solution without seeing your layout however if all items are built with the same layout then it is very simple to set the Checkboxes. For example to set Checkbox of item #2: Code: Copy 'assuming that the checkbox index is 1 in the layout. clv.GetPanel(3).GetView(1).Checked = Statemanger.Getsetting(“key2”) = True