Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I am developing a data bound control and am trying to handle the IBindingList.ListChanged event.

 

Originally, my control's constructor had

MyBindingList.ListChange += new ListChangedEventHandler(MyBindingList_ListChanged);

But the compiler didn't like it because when the control instance is first created, MyBindingList is null because it hasn't been assigned yet, and might not be for some time, or never if the user doesn't use data binding.

 

So I presume that I need to move my event wiring to the method that detects if my data source supports IBindingList. If the data source does, then wire the event. If it doesn't, then unwire the event.

 

Question #1: Am I on the right track?

Question #2: If so, how do I unwire an event?

 

The compiler didn't like MyBindingList.ListChanged =- ListChangedEventHandler; or variations on that theme.

 

object MyDataSource;    // Assigned elsewhere.
IBindingList MyBindingList;

private void AssociateBindingList()
{
   if (MyDataSource is IBindingList)
   {
       MyBindingList = (IBindingList)MyDataSource;
       MyBindingList.ListChanged += new ListChangedEventHandler(MyBindingList_ListChanged);
   }
   else
   {
       // Unwire old event if necessary somehow
       // HELP!!!!!!!
       MyBindingList = null;
   }
}

private void MyBindingList_ListChanged(object sender, ListChangedEventArgs e)
{
   // Refresh data
}

Suggestions? Pointers?

Thanks.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...