473,326 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

how to cancel checkChanged or click event for a checkbox?

Is there a cancel argument for cancelling if you want to check or uncheck a
checkbox?

In the checkChanged event of a checkbox I ask the user if they are sure they
want to check/uncheck something. If No, I want to cancel the check or
uncheck and cancel the click event. Right now I have a form level boolean
checkvar that I set based on the user's response. If No then when entering
the click event I don't perform various actions. Is there a way to prevent
the click event from happening if the user selects to Not continue with the
check change?

Thanks,
Rich
Aug 7 '07 #1
2 20889
On Aug 7, 12:22 pm, Rich <R...@discussions.microsoft.comwrote:
Is there a cancel argument for cancelling if you want to check or uncheck a
checkbox?

In the checkChanged event of a checkbox I ask the user if they are sure they
want to check/uncheck something. If No, I want to cancel the check or
uncheck and cancel the click event. Right now I have a form level boolean
checkvar that I set based on the user's response. If No then when entering
the click event I don't perform various actions. Is there a way to prevent
the click event from happening if the user selects to Not continue with the
check change?

Thanks,
Rich
Off the top of my head I would do this:

Private Sub checkBox_CheckedChanged(ByVal sender As Object, ByVal
e As EventArgs)
If MessageBox.Show("Are you sure", "Please Confirm",
MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.No Then
Dim cb As CheckBox = DirectCast(sender, CheckBox)
RemoveHandler cb.CheckedChanged, AddressOf
checkBox_CheckedChanged
cb.Checked = Not cb.Checked
AddHandler cb.CheckedChanged, AddressOf
checkBox_CheckedChanged
End If
End Sub

That should revert the checkbox to it's previous state if the user
does not confirm their choice. The RemoveHandler/AddHandler is used to
prevent the changing of the checkbox's checked state from triggering
the event handler recursively.

Thanks,

Seth Rowe

Aug 7 '07 #2
Thank you. I see your method will affect any checkbox on the form. The is
definitely more efficient than the other thing I tried.

I changed my form level boolean to a boolean within the click event of the
checkbox. upon clicking - the boolean takes on the value of the checkstate
-- this is to prevent the recursion thing as you noted. Then I ask the user
yes/no in the click event. If no, I set the checkstate to the opposite of
the boolean.

This appears to be working, and I do have several checkboxes, but this
particular one is the only one where the users asked me to implement this
checking mechanism.

With your mechanism, you only need to add the code once (and perhaps specify
which checkboxes to affect). My mechanism would require the same code for
all the checkboxes. . So even though, I only need this to happen to one
checkbox (for now), I think I will go with your mechansim.

Thanks again,
Rich

"rowe_newsgroups" wrote:
On Aug 7, 12:22 pm, Rich <R...@discussions.microsoft.comwrote:
Is there a cancel argument for cancelling if you want to check or uncheck a
checkbox?

In the checkChanged event of a checkbox I ask the user if they are sure they
want to check/uncheck something. If No, I want to cancel the check or
uncheck and cancel the click event. Right now I have a form level boolean
checkvar that I set based on the user's response. If No then when entering
the click event I don't perform various actions. Is there a way to prevent
the click event from happening if the user selects to Not continue with the
check change?

Thanks,
Rich

Off the top of my head I would do this:

Private Sub checkBox_CheckedChanged(ByVal sender As Object, ByVal
e As EventArgs)
If MessageBox.Show("Are you sure", "Please Confirm",
MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.No Then
Dim cb As CheckBox = DirectCast(sender, CheckBox)
RemoveHandler cb.CheckedChanged, AddressOf
checkBox_CheckedChanged
cb.Checked = Not cb.Checked
AddHandler cb.CheckedChanged, AddressOf
checkBox_CheckedChanged
End If
End Sub

That should revert the checkbox to it's previous state if the user
does not confirm their choice. The RemoveHandler/AddHandler is used to
prevent the changing of the checkbox's checked state from triggering
the event handler recursively.

Thanks,

Seth Rowe

Aug 7 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Paolo Mancini | last post by:
Hi all, I have a page with many different elements: <a href="...."> ... </a>, listboxes, radiobuttons, etc. Can I use javascript to prevent the user from interacting with the page? That is:...
7
by: MLH | last post by:
I tried the following code to prevent a checkbox from being updated (going from a value of Null to True, from True to False or from False to True). I was surprised it did not work. Can anyone...
2
by: Rodrigo Ferreira | last post by:
How can i cancel the click event of the mouse right button into a textbox? Greetings, Rodrigo Ferreira
2
by: Stephen Lambie | last post by:
Hi, I want to develop a custom checkbox. I want to use the existing checkbox in a custom control where I use the disabled state as a third state. I need to be able to detect mouse or click...
3
by: JD | last post by:
Hello, I have a problem with checkboxlist inside Repeater (in ASP.NET page). I am able to create Checkboxlist and bind it (inside Repeater_ItemBound - including setting checked/unchecked)....
1
by: dave | last post by:
I have a html table and mutliple rows. On each row i put an onclick event that opesn a modal window and prompts the user for some information. I want this modal window to show when the user...
1
by: Sergey Zuyev | last post by:
Hello all I have simple edit form. When user saves data that contains restricted characters such as (< , etc.) , regular expression validator will display a warning message. It all works fine,...
3
by: Gallarpri | last post by:
Hi, I'm making a dialog form with a textbox and 2 buttons: OK and Cancel. I want when I click on OK button, the program check the textbox, and if there is any error in the text introduced there,...
0
by: sambansi | last post by:
Hi All, on my web page i have button control and as per application's requirement i can't disable that. but when user clicked on it, the code should first check whether i am authorided user or...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.