Re: Changing Checkbox Values
There are two likely possibilities here. The first question I would ask is: Are you handling the CheckChanged event for these Checkboxes, and if so, how?
The second question is: How are you storing the information into the checkboxes? Since you are using a structure in a collection, that could be the source of the problem.
Re: Changing Checkbox Values
The checkbox objects are stored in the collection. The values of the check boxes are stored in a boolean array within the struct. I have verified that the struct values are correct. The problem is only introduced when I try to write back the values from the struct into the form using the above code.
Re: Changing Checkbox Values
Ok, so are you doing anything in CheckChanged?
The next thing to do is to put a breakpoint on the For Each line. Once you get there, step through one iteration of the loop while watching what values are coming from the structure. One of two things will happen:
1) If you are stepping with F11, you will find out that setting the checkbox is triggering some event that you weren't expecting that is subsequently screwing up the data.
2) You will find that the structure doesn't quite hold what you expected at the time of the call.
The next step is dependent on which of those are the case.
Re: Changing Checkbox Values
I figured out the problem. The pos = pos + 1 statement needs to be outside the if block to ensure that the variable is always incremented.
Thanks.
Re: Changing Checkbox Values
Why use a For Each loop and then increment a variable every iteration? Why not just use a For loop in the first place?