Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing combobox value back to original on Cancel 1

Status
Not open for further replies.

ookete

Programmer
Oct 5, 2004
180
US
This is probably a simple solution. I have a combobox that holds a list of products. Under certain conditions a change of product can effect the form, and I prompt the user for confirmation:
Code:
Private Sub cboProduct_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboProduct.SelectedIndexChanged

    Dim changeConfirm As DialogResult
    changeConfirm = MessageBox.Show("Are you sure?",, _
    MessageBoxButtons.YesNo)

    If changeConfirm = DialogResult.Yes Then
        ' run code
    End If

End Sub
However, when they hit No even though the code did not run, the comboox still holds the new value.

How do I actually prevent the combobox value from changing? Perhaps there is a different event I should use, or is there a PreviousValue method, or something like that?

Thanks a bunch.
 
No previous value Im afraid, though you might be able to use your underlying datasource to put the value back

Alternatively hold the value in a variable/property on the Enter Event of the combo, and put this value back if No is selected


Sweep
...if it works dont mess with it
 
you could capture the value in the Enter event in a class level variable, then apply that value after the yes/no box.

-Rick

----------------------
[banghead]If you're about to post an ASP.Net question,
please don't do it in the VB.Net forum[banghead]

[monkey] I believe in killer coding ninja monkeys.[monkey]
 
Also, I'm practicing for my upcoming role as Sweep's parrot ;) how am I doing?

-Rick

----------------------
[banghead]If you're about to post an ASP.Net question,
please don't do it in the VB.Net forum[banghead]

[monkey] I believe in killer coding ninja monkeys.[monkey]
 
You wanna cracker? :)

So I made the change as suggested and it works. The only problem is now the SelectedIndexChanged event is recursive... it is firing again when I change the value back to the old value, so I get the messagebox twice. I probably need to use a boolean to flag whether the change is an initial change or a reset.
 
Yup, the boolean flag should take care of it.

-Rick

----------------------
[banghead]If you're about to post an ASP.Net question,
please don't do it in the VB.Net forum[banghead]

[monkey] I believe in killer coding ninja monkeys.[monkey]
 
Rick

squawk...Thats the way to do it!..passing over a tasty cracker!


Sweep
...if it works dont mess with it
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top