Solved

Why does Checkbox Always Evaluate as False?

Posted on 2009-07-09
10
441 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.Net - TypeInitializer Error 25 26
Where did System.Data.Objects go? 2 27
Help with consolidating excel files using VB.net 2 23
ASP/VB email question 4 34
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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 Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

770 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