Hello group...
I've created a collection class that implements the following interfaces: IBindingList, IList, ICollection, IEnumerable and ITypedList:
abstract class DataCollectionBase : IBindingList, IList, ICollection, IEnumerable, ITypedList
{
private ArrayList innerList = null;
private System.Type itemType = null;
public DataCollectionBase()
{
this.innerList = new ArrayList();
}
protected System.Type ItemType
{
get { return this.itemType; }
set { this.itemType = value; }
}
// List Changed Notification
protected virtual void OnInsertComplete(int index, object newValue)
{
if (ListChanged != null)
{
ListChangedEventArgs args = new ListChangedEventArgs(ListChangedType.ItemAdded, index, -1);
ListChanged(this, args); // The StackOverflowException is thrown here
}
}
// IList Implementation
int IList.Add(object value)
{
int index = this.innerList.Add(value);
OnInsertComplete(index, value);
}
// IBindingList Implementation
public event ListChangedEventHandler ListChanged = null;
object IBindingList.AddNew()
{
object newItem = null;
// Here I create the new item with Reflection, based on the ItemType property and store a reference in 'newItem''.
((IList)this).Add(newItem);
return newItem;
}
}
I'm using my collection as a value for the DataSource property in a DataGrid control.
The IBindingList.AddNew() method works fine and the new item is instantiated via Reflection, but when I invoke the ListChanged event handler within the OnInsertComplete(..) method, the StackOverflowException is thrown.
I don't understand what's happening to my collection, the DataGrid control is the only component that's consuming the ListChanged event.
I really need your help...
Thank you all
Set a break point on OnInsertComplete() once your code reaches the
event firing, see if OnInsertComplete is being called recursively..
Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph
> Hello group...
>
[quoted text clipped - 64 lines]
>
> Thank you all...
Alx Sharp - 13 Oct 2004 17:45 GMT
Hi...
I already did that... I ran my program in debug mode and I went step by step
into every method call, but the exception is thrown the first time the
OnInsertComplete(..) method is invoked.
protected virtual void OnInsertComplete(int index, object value)
{
if (ListChanged != null)
{
ListChangedEventArgs args = new
ListChangedEventArgs(ListChangedType.ItemAdded, index, -1);
ListChanged(this, args); // The StackOverflowException is thrown
here
}
}
Thank you...
> Set a break point on OnInsertComplete() once your code reaches the event
> firing, see if OnInsertComplete is being called recursively..
[quoted text clipped - 58 lines]
>> I really need your help...
>> Thank you all...
Alx Sharp - 13 Oct 2004 18:10 GMT
Hello again...
If I add/remove items to or clear my collection before I use it as a data
source for the DataGrid control it works fine, actually, I'm consuming the
ListChanged event from the form the DataGrid is in, and I can show a
MessageBox every time the collection changes. The problem occurs when I set
the DataSource property to my collection, because the StackOverflowException
is thrown.
Thank you... and excuse me if I insist, but I really need this for an
important project...
> Set a break point on OnInsertComplete() once your code reaches the event
> firing, see if OnInsertComplete is being called recursively..
[quoted text clipped - 58 lines]
>> I really need your help...
>> Thank you all...
Alx Sharp - 13 Oct 2004 18:35 GMT
Hello and thank you all
I've found the problem... this is my item class named EditableObject:
class EditableObject : IEditableObject
{
protected bool isUndefined;
protected bool isEditing;
public EditableObject()
{
this.isUndefined = true;
this.isEditing = false;
}
// IEditableObject interface
public void BeginEdit()
{
if (!this.IsUndefined)
{
if (this.innerRow != null)
{
this.innerRow.BeginEdit();
}
this.isEditing = true;
this.isUndefined = false;
}
}
public bool IsEditing
{
get { return this.isEditing; }
}
public bool IsUndefined
{
get { return this.IsUndefined; } // Here's the problem, IsUndefined
instead of isUndefined (StackOverflowException) : )
}
}
When the collection is set as the data source for the DataGrid control and
the datagrid is focused, a new item is added and the BeginEdit() method
invoked.
This is a problem very hard to find, because I was focusing my atention to a
totally diferent part of my program...
Thank you all...
> Set a break point on OnInsertComplete() once your code reaches the event
> firing, see if OnInsertComplete is being called recursively..
[quoted text clipped - 58 lines]
>> I really need your help...
>> Thank you all...
Sijin Joseph - 14 Oct 2004 04:43 GMT
Cheers :)
Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph
> Hello and thank you all
>
[quoted text clipped - 107 lines]
>>> I really need your help...
>>> Thank you all...