473,387 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

how to cancel events for controls on a form when the form is closi

I have a C# app in VS2005. the form has a datetime picker with valuechanged
event. When the form closes, the valuechanged event is fired and an error is
thrown in its code when it tries to get a selected value from a combobox
which apparently doesn't exist anymore. I get around the problem with some
error handling, but what I really want to know, is there a way to cancel the
control event handlers on a form when the form is closing?
--
dchman
Jun 11 '06 #1
2 1726
dchman wrote:
I have a C# app in VS2005. the form has a datetime picker with valuechanged
event. When the form closes, the valuechanged event is fired and an error is
thrown in its code when it tries to get a selected value from a combobox
which apparently doesn't exist anymore. I get around the problem with some
error handling, but what I really want to know, is there a way to cancel the
control event handlers on a form when the form is closing?


It seems like the DateTime picker isn't clearing it's events when it has
to. Is it a bought component, or was it written by yourself?

ValueChanged events should not happen when closing and when the form is
invisible.

If it was a bought/3rd party control, then you can always unsubscribe
the event yourself in the form's closing event. Though this is a
workaround it should do the tricks without adding extra error handling:

form_Closing(...)
{
datepicker.ValueChanged -= datePicker_ValueChanged;
}

Jesse Houwing
Jun 11 '06 #2
Thanks for the quick response. I'll give your suggestion a try tomorrow.
The control is actually a common control supplied with VS2005.
--
dchman
"Jesse Houwing" wrote:
dchman wrote:
I have a C# app in VS2005. the form has a datetime picker with valuechanged
event. When the form closes, the valuechanged event is fired and an error is
thrown in its code when it tries to get a selected value from a combobox
which apparently doesn't exist anymore. I get around the problem with some
error handling, but what I really want to know, is there a way to cancel the
control event handlers on a form when the form is closing?


It seems like the DateTime picker isn't clearing it's events when it has
to. Is it a bought component, or was it written by yourself?

ValueChanged events should not happen when closing and when the form is
invisible.

If it was a bought/3rd party control, then you can always unsubscribe
the event yourself in the form's closing event. Though this is a
workaround it should do the tricks without adding extra error handling:

form_Closing(...)
{
datepicker.ValueChanged -= datePicker_ValueChanged;
}

Jesse Houwing

Jun 12 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: SDCII | last post by:
I have a UserControl derived class containing a textbox that wires the 'Validating' event. The textbox remains in focus when I cancel the validation, however another Usercontrol derived class on...
6
by: allyn44 | last post by:
HI--what I am trying to do is 2 things: 1. Open a form in either data entry mode or edit mode depending on what task the user is performing 2. Cancel events tied to fields on the form if I am in...
8
by: CJack | last post by:
hy, I have an mdi application, i create a child form and I want to know when a button is pressed while that child form is loaded. I have this code: private void frmTestBaby_KeyUp(object sender,...
0
by: PeacError | last post by:
Using Microsoft Visual Studio .NET 2003, Visual C# .NET 1.1: I apologize if this question has been addressed elsewhere, but I could not find a reference to it in the search engine for this...
14
by: clintonG | last post by:
This is an appeal for peer support sent to Microsoft as will be noted in closing. The Login control does not include a Cancel button. The only option is to convert the Login control to a...
3
by: Charles Law | last post by:
Under what circumstances would e.Cancel be set to True on entry to the Closing event of an MDI child form? I have found that this is why my application won't close properly. I can explicitly set...
6
by: Peter M. | last post by:
Hi all, If an event has multiple subscribers, is it possible to cancel the invocation of event handlers from an event handler? Or to be more specific: I'm subscribing to the ColumnChanging...
4
by: Academic | last post by:
Does it make sense to put this If e.Cancel Then Exit Sub at the beginning of form closing events so if the user cancels the app's exiting in one Closing routine he will not be asked again by...
13
Frinavale
by: Frinavale | last post by:
I've been trying all morning to cancel a form submit to the server. I have a JavaScript Object that determines whether or not the page should be submitted to the server depending on whether the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...

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.