Hi Johnny,
You should consider following Microsoft's standards for event design:
".NET Framework Developer's Guide, Event Design"
http://msdn2.microsoft.com/en-us/library/ms229011.aspx
Also, in the 2.0 framework you no longer need to create custom delegates.
Instead, you can use the generic EventHandler<TEventArgs> delegate if you
need to use custom event arguments. Create your own class that derives from
System.EventArgs and use it for the TEventArgs parameter.
--
Dave Sexton
"Johnny E Jensen" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi
> Using C#, VS2005 .NET2
>
> I have a custom usercontrol.
> Here i have a picturebox (Close) and a CheckedListBox
>
> A public delegate void for CloseControlHandler();, and event for that
> CloseControlEvent;
> A public delegate void for AddFieldToListHandler(string tablename, object
> item); and event for that AddFieldToListEvent;
>
> When the user clicks the picture, the picturebox.click event fires. Here I
> raises my CloseControlEvent, this allways works fine.
> When the user clicks on a item in the CheckListBox the
> CheckListBox.ItemCheck is fired (besause the CheckOnClick property =
> true), I call a method to raise my event AddFieldToListEvent, but always
> i'll get the 'Object reference not set....' Error. it seems that the
> AddFieldToListEvent i allways NULL.
> I do use the:
> If ( AddFieldToListEvent != null ) to prevent the application to crash.
>
> Could anyone provide with some hints.
>
> The Code:
> public delegate void AddFieldToListHandler(string tablename,
> FieldDescriptionClass description);
> public event AddFieldToListHandler AddFieldToListEvent;
>
> public delegate void CloseControlHandler(Control ClosingControl);
> public event CloseControlHandler CloseControlEvent;
>
> private void picClose_Click(object sender, EventArgs e)
> {
> if ( CloseControlEvent !=null)
> {
> CloseControlEvent(this);
> }
> }
>
> private void lstFields_ItemCheck(object sender, ItemCheckEventArgs e)
> {
> RaiseAddEvent(_strTablename, _objField);
> }
>
> private void RaiseAddEvent(string tablename, FieldDescriptionClass
> description)
> {
> if ( AddFieldToListEvent != null) // this AddFieldToListEvent is always
> null ?????????
> AddFieldToListEvent(tablename, description);
> }
>
> Kind Regards
> Johnny E Jensen
>
>