-
Mar 25th, 2012, 04:29 PM
#1
Thread Starter
Junior Member
Changing Checkbox Values
Hi,
I have an array of structs and each struct contains values for the checkboxes. I am trying to display the checkbox values contained within a particular struct.
MyStruct is an array of structs which has a values for the checkboxes
ChkBoxCol is the collection of check boxes for the form.
I am iterating through the collection as follows:
Code:
For Each ctrl In ChkBoxCol
If MyStruct(index).ChkBoxArray(pos) = True Then
CType(ctrl, CheckBox).Checked = True
pos = pos + 1
End If
Next
What I am noticing is that if the check boxes are checked in order (checkbox 1, 2, 3, 4...etc) the code works fine and the values are displayed correctly in the form. However, if the check boxes are not checked in order (4, 5, 7...etc) the code does not write the values of the check boxes and instead keeps them blank.
I just need to display the values for the check boxes for a specific struct.
-
Mar 25th, 2012, 04:40 PM
#2
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.
My usual boring signature: Nothing
-
Mar 25th, 2012, 05:03 PM
#3
Thread Starter
Junior Member
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.
-
Mar 25th, 2012, 05:13 PM
#4
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.
My usual boring signature: Nothing
-
Mar 30th, 2012, 10:27 PM
#5
Thread Starter
Junior Member
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.
-
Mar 31st, 2012, 01:39 AM
#6
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?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|