Solved

Why does Checkbox Always Evaluate as False?

Posted on 2009-07-09
10
439 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
  • 3
  • 2
  • 2
  • +3
10 Comments
 
LVL 27

Expert Comment

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

0
 
LVL 15

Expert Comment

by:spprivate
Comment Utility
If Chkbx.Checked = True Then

bla bla

Test this
0
 
LVL 14

Expert Comment

by:shahprabal
Comment Utility
Set a watch for chkbx.checked ... that should tell you when the property value changes since you start out by having it unchecked.
0
 
LVL 41

Expert Comment

by:guru_sami
Comment Utility
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
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 15

Expert Comment

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

Author Comment

by:brian_appliedcpu
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video discusses moving either the default database or any database to a new volume.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now