OnListChanged not called for ItemChanged unless databinding

Posts   
 
    
simmotech
User
Posts: 1024
Joined: 01-Feb-2006
# Posted on: 28-Nov-2012 18:32:04   

The check for ListChanged in this method is a problem if you override OnListChanged because it won't get called.

protected virtual void OnEntityInListOnEntityContentsChanged(object sender, EventArgs e)
{
  if (this.ListChanged == null)
    return;
  this.OnListChanged(this.IndexOf((T) sender), ListChangedType.ItemChanged);
}

(A further issue is that the very act of looking at these fields in the debugger cause the DefaultView to be created which sets ListChanged and so allows the event to fire! Took me ages to work out why it was working in the debugger but not in real code)

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 28-Nov-2012 20:38:35   

Please provide more info, check the forum guidelines for more details.

simmotech
User
Posts: 1024
Joined: 01-Feb-2006
# Posted on: 29-Nov-2012 08:40:15   

Sorry - thought this was a general question.

Designer: v3.5 final Runtime: v3.5.12.0330 Adapter, .NET 4 SQL Server 2008

Given that the code calls this method...

    protected virtual void OnListChanged(int index, ListChangedType typeOfChange)
    {
      if (this._surpressListChangedEvents)
        return;
      if (typeOfChange == ListChangedType.Reset)
        this._entityIndices = (Dictionary<Guid, int>) null;
      if (this.ListChanged == null)
        return;
      this.ListChanged((object) this, new ListChangedEventArgs(typeOfChange, index));
    }

... and would be a NOP anyway, I am guessing this is a time-saver to prevent calls to this.IndexOf((T) sender when nothing is listening?

If you can confirm that that is the only reason, I can get around that by overriding OnEntityInListOnEntityContentsChanged to always make the call.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 29-Nov-2012 10:27:49   

Confirmed.

Frans Bouma | Lead developer LLBLGen Pro