473,653 Members | 3,000 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

StackOverflowEx ception with the ListChanged event

Hello group...

I've created a collection class that implements the following interfaces: IBindingList, IList, ICollection, IEnumerable and ITypedList:

abstract class DataCollectionB ase : IBindingList, IList, ICollection, IEnumerable, ITypedList
{
private ArrayList innerList = null;
private System.Type itemType = null;

public DataCollectionB ase()
{
this.innerList = new ArrayList();
}

protected System.Type ItemType
{
get { return this.itemType; }
set { this.itemType = value; }
}

// List Changed Notification
protected virtual void OnInsertComplet e(int index, object newValue)
{
if (ListChanged != null)
{
ListChangedEven tArgs args = new ListChangedEven tArgs(ListChang edType.ItemAdde d, index, -1);
ListChanged(thi s, args); // The StackOverflowEx ception is thrown here
}
}

// IList Implementation
int IList.Add(objec t value)
{
int index = this.innerList. Add(value);
OnInsertComplet e(index, value);
}

// IBindingList Implementation
public event ListChangedEven tHandler ListChanged = null;

object IBindingList.Ad dNew()
{
object newItem = null;

// Here I create the new item with Reflection, based on the ItemType property and store a reference in 'newItem''.

((IList)this).A dd(newItem);
return newItem;
}
}

I'm using my collection as a value for the DataSource property in a DataGrid control.
The IBindingList.Ad dNew() method works fine and the new item is instantiated via Reflection, but when I invoke the ListChanged event handler within the OnInsertComplet e(..) method, the StackOverflowEx ception 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...
Nov 16 '05 #1
11 2890
Can you show us the ListChanged handler? StackOverflow => some (unintended,
unanticipated) loop that adds something with each iteration?
Nov 16 '05 #2
Hello Joep...

The ListChangedEven tHandler is part of the .NET Framework and it's declared
under the System.Componen tModel namespace as follows:

public delegate void ListChangedEven tHandler(object sender,
ListChangedEven tArgs e);

and the IBindingList interface includes an event of that type.

interface IBindingList : IList, ICollection, IEnumerable
{
// Properties go here

event ListChangedEven tHandler ListChanged;

// Methods go here
}

So, when my class implements the IBindingList interface I just have to write
something like this:

class DataCollectionB ase : IBindingList, IList, ICollection, IEnumerable,
ITypedList
{
public event ListChangedEven tHandler ListChanged = null;

protected virtual void OnInsertComplet e(int index, object newValue)
{
if(ListChanged != null)
{
ListChangedEven tArgs args = new
ListChangedEven tArgs(ListChang edType.ItemAdde d, index, -1);
ListChanged(thi s, args); // The StackOverflowEx ception is thrown
here
}
}
}

As you can see, (from my point of view) I'm not doing anything strange with
the event.
Only the DataGrid control consumes the event behind the scenes with
something like:

((IBindingList) DataSource).Lis tChanged += new
ListChangedEven tHandler(some_m ethod);

At least that's what I think, please right me if I'm wrong...

Thank you all again...

"Joep" <St***@DeStoep. nl> escribió en el mensaje
news:41******** *************@n ews.xs4all.nl.. .
Can you show us the ListChanged handler? StackOverflow => some
(unintended, unanticipated) loop that adds something with each iteration?

Nov 16 '05 #3
Could you perhaps provide the stack trace and, if possible, a short but
complete program[1] that exhibits your issue?
Its possible that there is something else in your application that is
causing the issue. Whittle down your code until it is nothing but the code
required to cause the problem. Although, contrary to the article, in this
case you would provide a GUI.

1. http://yoda.arachsys.com/csharp/complete.html (Its by Jon Skeet, another
C# MVP. I mention it only because the page itself is written in first person
and doesn't seem to mention who the author is.)
Nov 16 '05 #4
Hello Daniel...

The Stack Trace:

at System.Windows. Forms.DataGrid. AddNewRow()
at System.Windows. Forms.DataGridA ddNewRow.OnEdit ()
at System.Windows. Forms.DataGrid. Edit(String instantText)
at System.Windows. Forms.DataGrid. Edit()
at System.Windows. Forms.DataGrid. OnEnter(EventAr gs e)
at System.Windows. Forms.Control.N otifyEnter()
at System.Windows. Forms.Container Control.UpdateF ocusedControl()
I just wrote this line in my main form constructor, after the
InitializeCompo nent() call:

this.dataGrid1. DataSource = myCollection; // myCollection is of a class
derived from DataCollectionB ase, which I've described before...
// Right here the StackOverflowEx ception is thrown.
// I ran my application in Debug mode and I went step by step into every
method call until I reached the ListChanged(..) invocation (the origin of
the exception).

Thank you for your help...

"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> escribió en el
mensaje news:eb******** ******@TK2MSFTN GP12.phx.gbl...
Could you perhaps provide the stack trace and, if possible, a short but
complete program[1] that exhibits your issue?
Its possible that there is something else in your application that is
causing the issue. Whittle down your code until it is nothing but the code
required to cause the problem. Although, contrary to the article, in this
case you would provide a GUI.

1. http://yoda.arachsys.com/csharp/complete.html (Its by Jon Skeet,
another C# MVP. I mention it only because the page itself is written in
first person and doesn't seem to mention who the author is.)

Nov 16 '05 #5
Daniel O'Connell [C# MVP] <onyxkirx@--NOSPAM--comcast.net> wrote:
Could you perhaps provide the stack trace and, if possible, a short but
complete program[1] that exhibits your issue?
Its possible that there is something else in your application that is
causing the issue. Whittle down your code until it is nothing but the code
required to cause the problem. Although, contrary to the article, in this
case you would provide a GUI.
Not quite contrary to the article - it only says to remove GUI aspects
if they're unnecessary. A question *about* a GUI is fine to include a
GUI, of course - although it should be as pared down as possible.
1. http://yoda.arachsys.com/csharp/complete.html (Its by Jon Skeet, another
C# MVP. I mention it only because the page itself is written in first person
and doesn't seem to mention who the author is.)


That's a good point. Would you like me to rewrite it in the third
person, or perhaps put a "who wrote this" bit at the start?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #6

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Daniel O'Connell [C# MVP] <onyxkirx@--NOSPAM--comcast.net> wrote:
Could you perhaps provide the stack trace and, if possible, a short but
complete program[1] that exhibits your issue?
Its possible that there is something else in your application that is
causing the issue. Whittle down your code until it is nothing but the
code
required to cause the problem. Although, contrary to the article, in this
case you would provide a GUI.


Not quite contrary to the article - it only says to remove GUI aspects
if they're unnecessary. A question *about* a GUI is fine to include a
GUI, of course - although it should be as pared down as possible.


Ya ya, I know. Don't need to be semantically precise do we? :)

My reading of the article suggests avoiding a GUI where possible and I just
wanted to make it clear that it is entirely appropriate here(although *it*
might have been possible to prove the bug without a GUI, atleast until I saw
the stack trace. I think its unlikely at this point). Although I could have
pointed it out in a different way.

Sorry for implying an error in your article, however, ;)
1. http://yoda.arachsys.com/csharp/complete.html (Its by Jon Skeet,
another
C# MVP. I mention it only because the page itself is written in first
person
and doesn't seem to mention who the author is.)


That's a good point. Would you like me to rewrite it in the third
person, or perhaps put a "who wrote this" bit at the start?


Being in the first person is fine, but I think atleast some accreditation is
in order. Something as simple as a "By Jon Skeet" would suffice nicely.
I don't want to appear to be claiming your work, afterall, ;).

One other point, however. You might want to suggest, for GUI related
questions, that the author take the extra step and avoid using the forms
designer(or any designer, for that matter, except where the designer is in
question). Right now its not too big of a deal, however, with the coming of
partial classes the forms designer is going to be one PITA to copy and paste
in. I worry we'll start to see
public partial class MyClass
{
//...
}
public partial class MyClass
{
private void InitalizeCompon ent()
{
//...
}
}
or simply two attached files.
Nov 16 '05 #7
Daniel O'Connell [C# MVP] <onyxkirx@--NOSPAM--comcast.net> wrote:
Not quite contrary to the article - it only says to remove GUI aspects
if they're unnecessary. A question *about* a GUI is fine to include a
GUI, of course - although it should be as pared down as possible.
Ya ya, I know. Don't need to be semantically precise do we? :)

My reading of the article suggests avoiding a GUI where possible and I just
wanted to make it clear that it is entirely appropriate here(although *it*
might have been possible to prove the bug without a GUI, atleast until I saw
the stack trace. I think its unlikely at this point). Although I could have
pointed it out in a different way.

Sorry for implying an error in your article, however, ;)


No problem. I'll amend the article to make it clearer.
1. http://yoda.arachsys.com/csharp/complete.html (Its by Jon Skeet,
another
C# MVP. I mention it only because the page itself is written in first
person
and doesn't seem to mention who the author is.)


That's a good point. Would you like me to rewrite it in the third
person, or perhaps put a "who wrote this" bit at the start?


Being in the first person is fine, but I think atleast some accreditation is
in order. Something as simple as a "By Jon Skeet" would suffice nicely.
I don't want to appear to be claiming your work, afterall, ;).


Righto. Have a look in a few minutes and let me know if the change is
okay.
One other point, however. You might want to suggest, for GUI related
questions, that the author take the extra step and avoid using the forms
designer(or any designer, for that matter, except where the designer is in
question). Right now its not too big of a deal, however, with the coming of
partial classes the forms designer is going to be one PITA to copy and paste
in. I worry we'll start to see
public partial class MyClass
{
//...
}
public partial class MyClass
{
private void InitalizeCompon ent()
{
//...
}
}
or simply two attached files.


Yup. Even now it makes the code less readable, IMO - and the more the
designer is used, the more the temptation is to have more controls
which aren't actually required.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #8
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.isUndefine d = true;
this.isEditing = false;
}

// IEditableObject interface
public void BeginEdit()
{
if (!this.IsUndefi ned)
{
if (this.innerRow != null)
{
this.innerRow.B eginEdit();
}
this.isEditing = true;
this.isUndefine d = false;
}
}

public bool IsEditing
{
get { return this.isEditing; }
}

public bool IsUndefined
{
get { return this.IsUndefine d; } // Here's the problem, IsUndefined instead of isUndefined (StackOverflowE xception) : )
}
}

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...
Nov 16 '05 #9
Well, thtas good to hear.

That is another benifit of short but complete programs, if you write it and the error isn't there...there is ap retty good chance the error is elsewhere.

Glad you were able to solve your issue, however.
"Alx Sharp" <av*****@hotmai l.com> wrote in message news:OK******** *****@TK2MSFTNG P12.phx.gbl...
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.isUndefine d = true;
this.isEditing = false;
}

// IEditableObject interface
public void BeginEdit()
{
if (!this.IsUndefi ned)
{
if (this.innerRow != null)
{
this.innerRow.B eginEdit();
}
this.isEditing = true;
this.isUndefine d = false;
}
}

public bool IsEditing
{
get { return this.isEditing; }
}

public bool IsUndefined
{
get { return this.IsUndefine d; } // Here's the problem, IsUndefined instead of isUndefined (StackOverflowE xception) : )
}
}

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...
Nov 16 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1133
by: tolisss | last post by:
Hi to all i have some validation code inside ListChanged event and i have that collection bound to a grid. If i change a value on the grid the event fires ok. But if i change a value of the collection directly the event does not fire :(. Is that standard behaviour? *---------------------------------* Posted at: http://www.GroupSrv.com Check: http://wwww.HotCodecs.com *---------------------------------*
0
1393
by: Bijoy | last post by:
After Binding a Custom Collection as a Datasource , how is it possible to remove the references in the Property event ListChanged implemented by the IBindingList interface in our Custome collections. At the moment this is causing a bit of a worry since there ar Non-serializable references in the Property Listchanged eg. System.Windows.Forms.CurrencyManager and hence we arent able to pass our collection back to other layers (physically...
5
17265
by: Jesee | last post by:
I am reading Jeffrey Richter's book "Applied Microsoft .NET Framework programming",i came across "Exception handing". Page 405 says "If the stack overflow occurs within the CLR itself,your application code won't be able to catch the StackOverflowException exception and none of your finally blocks will excute.",I don't understand it. Following C# statement: class App { static void Main() {
12
4487
by: Amy | last post by:
I'm getting a System.StackOverflowException, and I can't see why. Here's the code that's throwing the exception. I don't see anyting that's recursive about it. Any help is appreciated (including help in debugging - I'm not sure what I'd put in a try or catch clause here): DataDealings sql = new DataDealings(); myProject = sql.GetProject(pID); -------------------------------------------------------------------------------------
8
2486
by: Lars-Erik Aabech | last post by:
Hi! I've got an asp.net page that works for all users except one and that one user only gets the error with a certain parameter set to a certain value. (Same value as the others, but for this one it fails). I manage to reproduce the error on my development computer, but it's completely impossible to debug or trace the error. The page had for some reason aspCompat set to true, and that gave a short stack trace, when set to false there's...
1
1844
by: John | last post by:
When sorting a datagrid by clicking its column header, a ListChanged event is raised by the dataview on that the datagrid is based. However, inside the ListChanged event handler, I loop through the dataview and see that the order of the dataview is not changed. I have a SequenceNumber column in that dataview and wish to reset the column when the datagrid is sorted. I don't want to loop through the datagrid, it's slow. Any suggesstions,...
10
14843
by: Mae Lim | last post by:
Dear all, I'm new to C# WebServices. I compile the WebService project it return no errors "Build: 1 succeeded, 0 failed, 0 skipped". Basically I have 2 WebMethod, when I try to invoke the first method it is working fine. Then when I try to invoke the second method it return me an error, Just In-Time Debugging, with error message "An exception 'System.StackOverflowException' has occurred in WebServices"
1
2078
by: Thomee Wright | last post by:
I'm having a problem with a pair of applications I'm developing. I have a server application which interacts with several instruments, and a client app which connects to the server and provides a UI for interacting with the instruments. Readings from the instruments are periodically sent to the clients, and clients will send commands to the server based on user input. In normal usage there will be around 6 clients connected, with a...
0
1714
by: Ray Holiday | last post by:
Hi, I'm using the DataView.ListChanged event to catch modifications to my table. But every time I update a row in my table the event fires has many time has I have columns. Since I have 55 columns and sometimes can be sending 3 updates within the same second, the event fires close to 170 times in the same second. I would like to received only one update notification per row rather than for every Item. I am using the...
0
8370
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8283
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8470
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8590
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5620
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4147
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4291
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2707
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1914
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.