Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted
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.
Posted
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

Posted

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

Live as if you were to die tomorrow. Learn as if you were to live forever.
Gandhi
Posted
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.

Posted
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.

Live as if you were to die tomorrow. Learn as if you were to live forever.
Gandhi
Posted (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 by PhilBayley

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...