PhilBayley Posted August 5, 2004 Posted August 5, 2004 Hi, This is probably really really easy, but I have hit a brick wall. I want to be able to cancel the change event of a radio button unless the user accepts a message box. Adding the message box to either the click event or the changed event is easy but how do I stop it either from happening if the user clicks cancel? Thanx PB Quote
mocella Posted August 5, 2004 Posted August 5, 2004 You can try using the radioButton.Validating() event - it accepts the cancel-event-args, so in that logic if all is not well, just do "e.Cancel = true;" to cancel the event at that point. Quote
PhilBayley Posted August 5, 2004 Author Posted August 5, 2004 You can try using the radioButton.Validating() event - it accepts the cancel-event-args' date=' so in that logic if all is not well, just do "e.Cancel = true;" to cancel the event at that point.[/quote'] cheers i will give it a go Quote
PhilBayley Posted August 5, 2004 Author Posted August 5, 2004 It kind of worked except that it calls the validating event when leaving the form so I have to answer my question twice. Does anyone have another option. PB Quote
techmanbd Posted August 5, 2004 Posted August 5, 2004 how about trying this in the radio button click event dim result as dialogresult result = messagebox.show(BLAH BLAH BLAH) If result = DialogResult.Cancel Then exit sub end if Quote Live as if you were to die tomorrow. Learn as if you were to live forever. Gandhi
PhilBayley Posted August 5, 2004 Author Posted August 5, 2004 how about trying this in the radio button click event dim result as dialogresult result = messagebox.show(BLAH BLAH BLAH) If result = DialogResult.Cancel Then exit sub end if Thanks tech - your code is pretty much as I have it but what if you press cancel it still actions the event i.e. if you are activating the radio button it will still be set to true if you press cancel or ok. Quote
techmanbd Posted August 5, 2004 Posted August 5, 2004 Thanks tech - your code is pretty much as I have it but what if you press cancel it still actions the event i.e. if you are activating the radio button it will still be set to true if you press cancel or ok. Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged If Me.RadioButton1.Checked Then Dim result As DialogResult result = MessageBox.Show("GGG", "FF",MessageBoxButtons.OKCancel) If result = DialogResult.Cancel Then Me.RadioButton1.Checked = False ElseIf result = DialogResult.OK Then ' CODE HERE FOR WHAT YOU WANT IT TO DO End If End If End Sub I am not exactly what you are loooking for but maybe this will work for you. If the button is checked then it will do all the things you want, if the operator clicks on cancel then it unchecks the radiobutton and then when it goes throug the event again since it is unchecked won't do the things you want it to do. Quote Live as if you were to die tomorrow. Learn as if you were to live forever. Gandhi
PhilBayley Posted August 6, 2004 Author Posted August 6, 2004 (edited) Thanks Techman, Your code kinda worked for what I wanted. I just had to write some functionality to remember which button was last checked and prompt for the dialog box dependant on that. I had thought of your idea but thought it may not be the correct way to do it as I was convinced that the event cancelling was the way forward. Cheers PB Edited August 6, 2004 by PhilBayley Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.