Problem getting CheckState of checkboxes from inside a class - vb.net

Dear Experts,

I have a class which contains a very simple routine which needs to get the status of some check boxes on my Form (i.e, checked, unchecked).

However,
I am unable to get the status - I will always get "FALSE" returned - even if the check boxes are checked.
(Please see my attached code)



If I'll put this routine inside my Form1, it will work - how can I solve this?

Thanks!
Dim ctrl As Control
        Dim checkbox As CheckBox
        For Each ctrl In form1.GroupBox2.Controls
if typeof(ctrl) Is Checkbox then       
     checkbox = ctrl
     MsgBox(checkbox.Checked)
end if
Next

Open in new window

nahumbaAsked:
Who is Participating?
 
ChumadConnect With a Mentor Commented:
Do you re-load the checkbox list in the page_load? If you do, that is going to reset any checked values. You need to check for page.IsPostBack and only load your checkbox list if it evaluates to FALSE...

if not page.isPostBack then
   'load list boxes'
end if
0
 
nahumbaAuthor Commented:
Hi,
No, Im not reloading them on the page_load event...


thanks
0
 
ChumadCommented:
What happens if you refer to the checkbox by it's ID instead of looping? Do you get the expected result? Also, if you move this little method to the very top of your page_load, what happens? I'm just trying to diagnose problems to find out what's going on... not really saying these are permanent solutions.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
Jaime OlivaresConnect With a Mentor Software ArchitectCommented:
>>No, Im not reloading them on the page_load event...
Is this an ASP.net question?
0
 
nahumbaAuthor Commented:
Hi Guys,

1) I did try to put this method on the very top of my page_load - works fine... the problem is that I must call this method from inside a class in a different module.

2) This is not an ASP.net application.

Thanks again!
0
 
nahumbaAuthor Commented:
Hi guys,

I'm sorry - that was MY mistake... Apparently I was calling this method from a different thread - this is obviously the reason for my problem!

Thanks again!

0
All Courses

From novice to tech pro — start learning today.