Click here to Skip to main content
15,895,557 members
Home / Discussions / C#
   

C#

 
GeneralRe: IMalloc vs Release Pin
Judah Gabriel Himango16-Mar-04 10:05
sponsorJudah Gabriel Himango16-Mar-04 10:05 
GeneralENGLISH! My grammer sucks :P Pin
Tristan Rhodes16-Mar-04 11:03
Tristan Rhodes16-Mar-04 11:03 
GeneralRe: ENGLISH! My grammer sucks :P Pin
Judah Gabriel Himango16-Mar-04 11:31
sponsorJudah Gabriel Himango16-Mar-04 11:31 
GeneralDelegates and EventHandlers Pin
MrEyes16-Mar-04 5:57
MrEyes16-Mar-04 5:57 
GeneralRe: Delegates and EventHandlers Pin
Jeremy Kimball16-Mar-04 6:31
Jeremy Kimball16-Mar-04 6:31 
GeneralRe: Delegates and EventHandlers Pin
MrEyes16-Mar-04 7:45
MrEyes16-Mar-04 7:45 
GeneralRe: Delegates and EventHandlers Pin
Jeremy Kimball16-Mar-04 9:04
Jeremy Kimball16-Mar-04 9:04 
GeneralRe: Delegates and EventHandlers Pin
Heath Stewart16-Mar-04 6:38
protectorHeath Stewart16-Mar-04 6:38 
A few questions...

I take it that new ControlVars.gridEvents(ComboBox_GridEvent1) (or similar) would return a new delegate that points to the method?

Also, what exactly isn't working? If I'm assuming the statement above correctly, this seems like it should work. When you start attaching handlers (delegates) to the events, so long as you specify the key that corresponds to the event, this should hook-up the handler to the event that is defined in your Form class. The .NET FCL assemblies actually use a similar approach in many places (explicitly defining a hashtable or collection for event handlers as opposed to letting the compiler do it automatically).

So, to set the handler in the first block of code, you'd have something like:
myComboBox.SelectedIndexChanged +=
  EventDelegates["ComboBox.SelectedIndexChanged"]
Here I'm making things a little easier and assuming that you change the hash key to something easier to associate (like {TypeName.EventName}).

If you wanted to handle hook up handlers at runtime using discovery, you could do something like this (note: not optimized - only an example):
Type t = myControl.GetType();
EventInfo[] events = t.GetEvents(BindingFlags.Instance | BindingFlags.Public);
foreach (EventInfo event in events)
{
  string name = string.Format("{0}.{1}", t.Name, event.Name)'
  if (EventDelegates.ContainsKey(name))
    event.AddEventHandler(myControl, EventDelegates[name]);
}


 

Microsoft MVP, Visual C#
My Articles
GeneralActive Directory hotswap policy Pin
UltraKev16-Mar-04 4:41
UltraKev16-Mar-04 4:41 
GeneralRe: Active Directory hotswap policy Pin
Heath Stewart16-Mar-04 5:02
protectorHeath Stewart16-Mar-04 5:02 
GeneralRe: Active Directory hotswap policy Pin
UltraKev16-Mar-04 5:14
UltraKev16-Mar-04 5:14 
GeneralRe: Active Directory hotswap policy Pin
Heath Stewart16-Mar-04 5:25
protectorHeath Stewart16-Mar-04 5:25 
Generalmanaged c++ vs. c# Pin
Anonymous16-Mar-04 4:38
Anonymous16-Mar-04 4:38 
GeneralRe: managed c++ vs. c# Pin
Judah Gabriel Himango16-Mar-04 4:56
sponsorJudah Gabriel Himango16-Mar-04 4:56 
GeneralRe: managed c++ vs. c# Pin
Heath Stewart16-Mar-04 5:06
protectorHeath Stewart16-Mar-04 5:06 
GeneralRe: managed c++ vs. c# Pin
Judah Gabriel Himango16-Mar-04 5:38
sponsorJudah Gabriel Himango16-Mar-04 5:38 
GeneralRe: managed c++ vs. c# Pin
Heath Stewart16-Mar-04 4:59
protectorHeath Stewart16-Mar-04 4:59 
GeneralRe: managed c++ vs. c# Pin
Nemanja Trifunovic16-Mar-04 5:17
Nemanja Trifunovic16-Mar-04 5:17 
GeneralRe: managed c++ vs. c# Pin
Jeremy Kimball16-Mar-04 6:34
Jeremy Kimball16-Mar-04 6:34 
GeneralDllImport Without Attribute Pin
Werdna16-Mar-04 4:06
Werdna16-Mar-04 4:06 
GeneralRe: DllImport Without Attribute Pin
Heath Stewart16-Mar-04 4:19
protectorHeath Stewart16-Mar-04 4:19 
GeneralRe: DllImport Without Attribute Pin
Jeremy Kimball16-Mar-04 6:46
Jeremy Kimball16-Mar-04 6:46 
Generaladd Xml in C# Pin
bertcox16-Mar-04 2:37
bertcox16-Mar-04 2:37 
GeneralRe: add Xml in C# Pin
rull16-Mar-04 3:34
rull16-Mar-04 3:34 
GeneralRe: add Xml in C# Pin
Philip Fitzsimons16-Mar-04 3:38
Philip Fitzsimons16-Mar-04 3:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.