Solved

Why does Checkbox Always Evaluate as False?

Posted on 2009-07-09
10
442 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
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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

790 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