Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Why does Checkbox Always Evaluate as False?

Posted on 2009-07-09
10
Medium Priority
?
446 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
Technology Partners: 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 2000 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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

610 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