Windows Develop Bookmark and Share   
 index > Windows Forms General > forcing an event
 

forcing an event

I have added an event handler that should execute each time the position in a dataset is changed. The event must also be fired when the dataset is initialized. Unfortunately setting the currency to the initial postion of "0" does not fire the event. My work around has been to increment/decrement the postion but this doesn't seem very clean to me. How can I force an event to fire in general and in this case in particular?

currency = BindingContext[da.StationDataView];
currency.PositionChanged += new EventHandler(Binding_PositionChanged);
currency.Position = 0;
//currency.Position++;   
//currency.Position--;
MigrationUser 1  Monday, January 12, 2004 7:13 AM
I would think you would just have to setup your handler before you fill the source. 

That way when the source fills it will change position (unless there is not records in the source anyways (which your code would error if you left it that way).

MigrationUser 1  Thursday, January 22, 2004 9:27 PM
The handler is set up before the source (see sample code).
In fact the handler is fired if I execute the code 

currency.Position++; 
currency.Position--; 

This isn't very elegant since event handler is fired twice. I would rather it be fired just once but "currency.Position = 0;" doesn't fire it at all. 

This is why I would like to be able to force an event programatically.
MigrationUser 1  Friday, January 23, 2004 7:07 AM
have you tried setting it to 

currency.position = -1
MigrationUser 1  Friday, January 23, 2004 12:45 PM

You can use google to search for other answers

Custom Search

More Threads

• Command Object Problem (ExecuteScalar)
• Image on Splitter Control
• Project Outut Question, Please Help.
• Accessing Form controls from another code file
• How create hotkey that doesn't require control to have focus?
• Control.Invoke/BeginInvoke Deadlock
• how to use masktextBox with dates with localization
• Application Settings Problem: 1 of 5 doesn't work
• multi-language in windows form 2.0
• Making A Label Resizable? Possible?