Removing child objects from a grid (GridEx)

Removing child objects from a grid (GridEx)

Old forum URL: forums.lhotka.net/forums/t/346.aspx


Skinny posted on Monday, June 12, 2006

Hi All,

After trying to find the cause myself, I decided to post my problem here. I'm using Janus GridEx in combination with a simple (for test purposes) custom collection based on the BusinessListBase. This collection is called "MyOrderLines"  and contains "MyOrderLine" objects.

Adding, removing (and setting properties) child items from code works fine, but as soon as I try to use this collection as a DataSource for my grid an exception is thrown when I try to cancel out of adding a new line to the collection:

"Index must be non-negative and smaller then the size of the collection"

I traced the exception down to the following line in the "OnPropertyChanged" method of BindableBase:

if (nonSerializableHandlers != null)
nonSerializableHandlers.Invoke(this,
new PropertyChangedEventArgs(propertyName));

If I try to step in to this function, a couple of "Equal" calls are fired for every child object, but after that the exception is thrown. Below is the definition of my Child object.

When using the standard Microsoft DataGridView, everything seems to work fine, so it must have something to do with the order of events that the GridEx is firing, but I'm currently unable to determine the exact cause.

Hopefully someone can give me a hint about where to look further, but for now I'm out of debugging options.

Regards,
Mark

-------------------------

public class MyOrderLine : BusinessBase<MyOrderLine>
{

private static int _lastID = 0;
private int _lineID = -1;
private int _productID = 0;

public override int GetHashCode()
{
 
return _lineID.GetHashCode();
}

protected override object GetIdValue()
{
  return _lineID;
}

public int LineID
{
  get { return _lineID; }
}

public int ProductID
{
  get { return _productID; }
  set
  {
   
if (_productID != value)
    { 
      
_productID = value;
      PropertyHasChanged(
"ProductID");
    }
  }
}

internal static MyOrderLine NewOrderLine()
{
 
return new MyOrderLine();
}

private MyOrderLine()
{
 
_lineID = _lastID - 1;
 
_lastID = _lineID;
  
MarkAsChild();
}

}

 

Copyright (c) Marimer LLC