Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET Interface and Graphics > Cancel Event - Decent Work Around


Reply
 
Thread Tools Display Modes
  #1  
Old 05-18-2004, 07:19 AM
puccij puccij is offline
Freshman
 
Join Date: Apr 2004
Location: Columbus Ohio
Posts: 31
Default Cancel Event - Decent Work Around


I have a combobox on a form. When the selected value changes I want to repopulate a number of iother values on the form, but first I want to check to see if the user wants to save changes.

The problem is that this often will require that the code cancel the click event which as far as I can tell is not possible. If you use the vailidating event the code only fires when the combo loses focus.

The only work around I have seen posted is to capture the old selected index and reset the value if a "cancel" event is needed.

I have another suggestion that seems fairly obvious. I am simply putting the cancel code in the validating event, but also adding code to the click event that selects the next c ontrol on my form. This has the effect of instantly triggerring the valding event.

It ain't pretty but it's getting the job done.


Code:
Private Sub ComboChange(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles ComboBox1.Validating If CheckDataSave then e.Cancel = true End Sub Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged, ComboBox2.SelectedIndexChanged nextcontrol.Select End Sub
Reply With Quote
  #2  
Old 05-18-2004, 12:25 PM
Machaira's Avatar
Machaira Machaira is offline
Jedi Coder

* Expert *
 
Join Date: Aug 2002
Location: Abingdon, MD
Posts: 3,438
Default

Why not just do:
Code:
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged, ComboBox2.SelectedIndexChanged CheckDataSave nextcontrol.Select End Sub
or some variation of this? If you're allowing the user to cancel the selection of the new selection in the CheckDataSave then you can do:
Code:
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged, ComboBox2.SelectedIndexChanged If CheckDataSave Then nextcontrol.Select End Sub
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
can i make cancel button work with this code ruffleader General 7 11-07-2003 01:01 PM
Cancel update ADO IceMan7255 Database and Reporting 1 03-09-2003 06:19 PM
textbox selchange event carma General 2 10-27-2002 12:48 AM
Someone Help Me With My Message Boxes Please!! Tajiri17 General 12 03-02-2002 11:29 AM
KeyUp Event does not work with MSFlexGrid sethindeed General 3 07-03-2001 09:12 AM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->