aewarnick Posted May 27, 2003 Posted May 27, 2003 I must have done something wrong, but what? //This is my handler and EventArgs. //They were declared inside the namespace block of my custom control. public delegate void ItemSelectedEventHandler(object sender, ItemSelectedEventArgs e); public class ItemSelectedEventArgs : EventArgs { public int Index=-1; public string Item=""; public ItemSelectedEventArgs() { Index= FileBrowserLB.selIndex; Item= FileBrowserLB.selFile; } } //This is the event variable declared inside the controls constructor: public event ItemSelectedEventHandler ItemSelected; The rest of the code is from a form class that has the custom control on it. //In the forms constructor: this.fileBrowser.ItemSelected += new ItemSelectedEventHandler(this.ItemSel); //The method in the form that should capture the event: void ItemSel(object sender, ItemSelectedEventArgs e) { MessageBox.Show(e.Index+" "+e.Item); } The messageBox never pops up indicating that the event does not work. However, it works inside the control but just not outside in another class. What am I missing? Quote C#
Administrators PlausiblyDamp Posted May 31, 2003 Administrators Posted May 31, 2003 Where are you raising the event? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
aewarnick Posted May 31, 2003 Author Posted May 31, 2003 (edited) a Method I made inside the control that has nothing in it. I did not know what to put in it. This is the call to it: this.OnItemSelected(new ItemSelectedEventArgs()); Is there some special code to make event handlers fire that I don't know about? The problem is that I don't know how to make the event raise when it is in another form. Edited May 31, 2003 by aewarnick Quote C#
aewarnick Posted June 2, 2003 Author Posted June 2, 2003 Thhhhiiiiiisss was soooo simple!! Why did noone tell me about this. The documentation I found on the internet did not include this!!!!!!!!!!!!!!!!! this.Invoke(ItemSelected, new object[]{this, new ItemSelectedEventArgs()}); intead of using this.OnItemSelected(new ItemSelectedEventArgs()); I found this out by curiosity alone! Quote C#
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.