How to make the checkbox stays checked when double click

  • Hi everyone...

    I believe this is not sql hehehehe...

    how should i make the checkbox stays check...

    This is my code....

    Public Class frmTest

    Private Sub frmTest_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    CheckBox1.CheckState = CheckState.Checked

    End Sub

    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged

    If CheckBox1.Checked Then

    CheckBox2.CheckState = CheckState.Unchecked

    CheckBox3.CheckState = CheckState.Unchecked

    End If

    End Sub

    Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged

    If CheckBox2.Checked Then

    CheckBox1.CheckState = CheckState.Unchecked

    CheckBox3.CheckState = CheckState.Unchecked

    End If

    End Sub

    Private Sub CheckBox3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox3.CheckedChanged

    If CheckBox3.Checked Then

    CheckBox1.CheckState = CheckState.Unchecked

    CheckBox2.CheckState = CheckState.Unchecked

    End If

    End Sub

    End Class

    but when i try to double click the checkbox, the check is gone, it will not stay as is..

    thanks...

    USC CAS CHEERDANCE TEAM 🙂

  • One does not double-click a check box. A single-click does the trick. Double-clicking a check box checks it then unchecks it right away.

  • I will go one step further and think outside the checkbox. 😉

    You seem to have 3 checkboxes that you want to allow only one of them to be selected at a time. I would suggest that you are using the wrong control here. Try using a radio button group instead. You can add a 4th option to the group for "None" which will simulate having none of them checked.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • OCTom (10/4/2013)


    One does not double-click a check box. A single-click does the trick. Double-clicking a check box checks it then unchecks it right away.

    Hi

    It seems you did not get my point, I know that when you doulble click a checkbox it will be uncheck..

    What i mean brothers and sisters is that, HOW TO MAKE IT STAYS CHECK EVEN IF I DOUBLE CLICK IT, IT WILL ALWAYS STAYS CHECK NOT UNCHECK!!!!!

    ok?...

    cheers:-)

  • Sean Lange (10/4/2013)


    I will go one step further and think outside the checkbox. 😉

    You seem to have 3 checkboxes that you want to allow only one of them to be selected at a time. I would suggest that you are using the wrong control here. Try using a radio button group instead. You can add a 4th option to the group for "None" which will simulate having none of them checked.

    Hi Sean

    Yes, right before you suggested it to use radio button, i already think of it, BUT i want checkboxes to behave like radio button(thou it seem stupid but i have my own reason why i am using it)

  • enriquezreyjoseph (10/4/2013)


    OCTom (10/4/2013)


    One does not double-click a check box. A single-click does the trick. Double-clicking a check box checks it then unchecks it right away.

    Hi

    It seems you did not get my point, I know that when you doulble click a checkbox it will be uncheck..

    What i mean brothers and sisters is that, HOW TO MAKE IT STAYS CHECK EVEN IF I DOUBLE CLICK IT, IT WILL ALWAYS STAYS CHECK NOT UNCHECK!!!!!

    ok?...

    cheers:-)

    No need to yell. We understand what you are trying to do. The point being made is that by default a checkbox does not have a doubleclick event, mostly because it doesn't make sense for that control. You can add your own but as I stated earlier you should use radio buttons.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • enriquezreyjoseph (10/4/2013)


    Sean Lange (10/4/2013)


    I will go one step further and think outside the checkbox. 😉

    You seem to have 3 checkboxes that you want to allow only one of them to be selected at a time. I would suggest that you are using the wrong control here. Try using a radio button group instead. You can add a 4th option to the group for "None" which will simulate having none of them checked.

    Hi Sean

    Yes, right before you suggested it to use radio button, i already think of it, BUT i want checkboxes to behave like radio button(thou it seem stupid but i have my own reason why i am using it)

    Using check boxes in this case is using the wrong tool for the job. You are making this a lot harder on yourself than you need to. Look at all the code you have already had to write just to deal with the fact that you are using a series of check boxes for a mutually exclusive decision.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • enriquezreyjoseph (10/4/2013)


    BUT i want checkboxes to behave like radio button(thou it seem stupid but i have my own reason why i am using it)

    That's generally a bad idea. Anyone who's used windows and windows applications knows how checkboxes behave. When you change that behaviour, you now have a UI that does not behave as people expect it to. They'll struggle to use it, they'll log bug reports saying that the check boxes don't behave properly, etc.

    Principal of UI design - stay consistent (and that's consistent within the app and with OS outside the app)

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply