Results 1 to 4 of 4

Thread: [RESOLVED] CheckBox Error

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2011
    Posts
    340

    Resolved [RESOLVED] CheckBox Error

    Code:
    Private Sub CheckBox1_CheckChanged(sender As System.Object, e As System.EventArgs) Handles CheckBox1.CheckChanged
    
    If TextBox1.Text = "Default" Then
                MessageBox.Show("Default")
                CheckBox1.Checked = False
            Else
    MsgBox("Not Default")
    End If
    End Sub
    by default, the checkbox is not checked. now when i click the checkbox, I want it to do the above code.

    if the box says "default", i want it to msgbox default, and then uncheck the check box. (it is automatically checked after i click it)

    problem is, the msgbox pops up twice. any help.

  2. #2
    Addicted Member
    Join Date
    Nov 2011
    Posts
    177

    Re: CheckBox Error

    That's because when CheckBox1.Checked = False i ran it activates the event CheckChanged again.
    Try MouseClick Event..
    Last edited by m.davide; Feb 8th, 2012 at 09:34 PM.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: CheckBox Error

    If you only want to execute some code when the CheckBox is checked, shouldn't you have some code in their to test whether it is checked or unchecked? That event is raised in both cases, so if you want to differentiate between the two you must do so with your own code.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2011
    Posts
    340

    Re: CheckBox Error

    Oh duh. Thanks, got it working! I must be sleepy if I didn't see that..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width