473,770 Members | 2,004 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 21044
On Aug 7, 12:22 pm, Rich <R...@discussio ns.microsoft.co mwrote:
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_Checke dChanged(ByVal sender As Object, ByVal
e As EventArgs)
If MessageBox.Show ("Are you sure", "Please Confirm",
MessageBoxButto ns.YesNo) = Windows.Forms.D ialogResult.No Then
Dim cb As CheckBox = DirectCast(send er, CheckBox)
RemoveHandler cb.CheckedChang ed, AddressOf
checkBox_Checke dChanged
cb.Checked = Not cb.Checked
AddHandler cb.CheckedChang ed, AddressOf
checkBox_Checke dChanged
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_newsgroup s" wrote:
On Aug 7, 12:22 pm, Rich <R...@discussio ns.microsoft.co mwrote:
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_Checke dChanged(ByVal sender As Object, ByVal
e As EventArgs)
If MessageBox.Show ("Are you sure", "Please Confirm",
MessageBoxButto ns.YesNo) = Windows.Forms.D ialogResult.No Then
Dim cb As CheckBox = DirectCast(send er, CheckBox)
RemoveHandler cb.CheckedChang ed, AddressOf
checkBox_Checke dChanged
cb.Checked = Not cb.Checked
AddHandler cb.CheckedChang ed, AddressOf
checkBox_Checke dChanged
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
9756
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: can I intercept, alert the user, and cancel any click event on the page? Unfortunately, if the user clicks on a page element, the event bubbles
7
2517
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 offer a sensible, logical, insightful reason as to why Microsoft does not want to let programmers stop this event? Private Sub NoOwnerInfoChkBox_Click() If CurrentVehicleJobID = 0 Then
2
1243
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
2057
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 events in the disabled checkbox or the parent custom control. Is this possible? How does a control like a button control implement event trapping like a click event?
3
6703
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). Checkboxlist has Autopostback=true so whenever I click on checkbox, the page is submitted to the server. Here starts my problem: I am not able to capture the click event of checkbox list to find out which checkbox was clicked (which generated click...
1
2108
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 clicks anything on that row. I have a few checkboxes in the row cells. The click event first fires on the checkbox and then the row (opening the modal window after the checkbox is checked). How can I force the modal window to open first and...
1
3913
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, but if users decides to exit the form using Cancel button then error occurs: A potentially dangerous Request.Form value was detected from the client. The Cancel button has CausesValidation set to false. Is there any way to avoid this error...
3
11951
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, then it shows a MessageBox and cancel the click event, so the dialog form won't close. How can I cancel the click event on a button? I have looked at "EventArgs e", but it hasnt any property to cancel the vent.
0
2276
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 not? if not then it should not execute the remaining code. i can slove this by simple putting if condition. but i want make use of button click event parameter (object and system.eventArgs). can any one tell me how can i stop / cancle click event...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10259
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9906
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7456
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2849
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.