Solved

Why does Checkbox Always Evaluate as False?

Posted on 2009-07-09
10
443 Views
Last Modified: 2013-11-26
Have a WinForm with checkbox control and the following property settings:

          Name: Chkbx
     AutoCheck: True
       Checked: False
    CheckState: Unchecked

Button on same WinForm with these settings:

    Name: btnOK
    Text: OK

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        If Me.Chkbx.Checked Then
            MsgBox("True")
        Else
            MsgBox("False")
        End If
    End Sub

Regardless if the checkbox is checked or unchecked, the button click always returns msg of False. What am I doing wrong?
0
Comment
Question by:brian_appliedcpu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +3
10 Comments
 
LVL 27

Expert Comment

by:VBRocks
ID: 24817915
Works perfect for me...  Any chance you could have the wrong checkbox?

0
 
LVL 15

Expert Comment

by:spprivate
ID: 24818073
If Chkbx.Checked = True Then

bla bla

Test this
0
 
LVL 14

Expert Comment

by:shahprabal
ID: 24818609
Set a watch for chkbx.checked ... that should tell you when the property value changes since you start out by having it unchecked.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 41

Expert Comment

by:guru_sami
ID: 24818804
Are you by any chance setting Chkbx.Checked= false in the Page_Load or somewhere?
Do you mind sharing all code wherever Chkbx is referenced...
0
 
LVL 6

Expert Comment

by:badalpatel
ID: 24822254
i think in page_load u r unchecking the checkbox..
To uncheck the checkbox in page_load


If Not Page.IsPostBack Then
          Chkbx.Checked = False
End If

Open in new window

0
 
LVL 15

Expert Comment

by:spprivate
ID: 24823430
Guys
Brian is using a windows application.Where does the page load come from here.
0
 
LVL 2

Author Comment

by:brian_appliedcpu
ID: 24824921
The only code I have in my WinForm is this.

Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        If Me.Chkbx.Checked Then
            MsgBox("True")
        Else
            MsgBox("False")
        End If
    End Sub

Testing for
        If Me.Chkbx.Checked = True Then
yiields the same result; The code always throws the False msgbox, even when the checkbox is checked. If I set a breakpoint on the IF statement and step thru ithe code, it always processes the Else condition, regardless if the checkbox is checked or unchecked.

I running VS2005. Is there a way that I can verify that I have the latest install and current service packs, etc?
0
 
LVL 14

Expert Comment

by:shahprabal
ID: 24825077
This is not something that would be fixed in a service pack or a later .net framework version. It is definitely not a VS bug either. I suggest that you add a watch not a breakpoint for Chkbx.Checked. Put a breakpoint in form_load (if you dont have form_load add it with a simple dim i as integer statement and put a breakpoint there). Also add another checkbox and see if you are just having this issue with a particular checkbox or all of them.
0
 
LVL 2

Author Comment

by:brian_appliedcpu
ID: 24826934
As a test, I created a brand new project, and I don't have the problem within the new project.

Can VS projects become corrupt? Is there a way to "clean up" or "repair" a project? Can I simply add all the objects from my original  project to the new project in order to avoid any possible corruption (if that is, in fact, the problem)?

Thanks.
0
 
LVL 14

Accepted Solution

by:
shahprabal earned 500 total points
ID: 24827175
Usually only thing the projects that gets out of wack are the references. You can right click the project and click Clean, then rebuild the project. Look at errors and warnings if any. If this doesn't do the trick then create a new project and right click the project > Add > Add Exisiting Item and add your items to the project.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question