Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm Data Binding / October 2004

Tip: Looking for answers? Try searching our database.

problem with databinding collection to datagrid

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jeff B - 27 Aug 2004 17:29 GMT
Hi
I have a collection that inherits from collectonbase, implements
IBindingList. and is serlizable.
I am binding the collection to a Datagrid using a tablestyle to limit the
data the datagrid displays. I can bind to the collection successfully.
If my collection has one object. When I click on the new row, it adds an
object with the addnew method as it should. If I then click on an existing
row the new row (where I did not enter any information) shows as a new row
(*) again, but the collection still has the new object appended to it (two
objects in total). If I then click on the new row, again, the collection
adds an object (now having 2 new object).  If I reclick on an existing row,
again the new appended row returns to the new state (*), showing only one
existing object, but the collection has three.

Has anybody had an issue like this.
Am I missing an interface that the datagrid needs to synchronize
successfully with the bound collection.
HELP!!

Jeff B.
Ken Tucker [MVP] - 28 Aug 2004 12:11 GMT
Hi,

           Try having the class stored in the collection implement
ieditableobject.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlr
fsystemcomponentmodelieditableobjectclasstopic.asp


Ken
----------------------------
Hi
I have a collection that inherits from collectonbase, implements
IBindingList. and is serlizable.
I am binding the collection to a Datagrid using a tablestyle to limit the
data the datagrid displays. I can bind to the collection successfully.
If my collection has one object. When I click on the new row, it adds an
object with the addnew method as it should. If I then click on an existing
row the new row (where I did not enter any information) shows as a new row
(*) again, but the collection still has the new object appended to it (two
objects in total). If I then click on the new row, again, the collection
adds an object (now having 2 new object).  If I reclick on an existing row,
again the new appended row returns to the new state (*), showing only one
existing object, but the collection has three.

Has anybody had an issue like this.
Am I missing an interface that the datagrid needs to synchronize
successfully with the bound collection.
HELP!!

Jeff B.
Jacob S - 09 Sep 2004 06:33 GMT
You can find a sample code in this thread

http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=FBimDanzDHA
.3564%40cpmsftngxa07.phx.gbl

Jacob

> Hi,
>
[quoted text clipped - 25 lines]
>
> Jeff B.
BorisDotNet - 10 Sep 2004 01:07 GMT
The implementation of IBindingList in this example is not entirely correct.
That is probably why this example has been removed from the current version
of MSDN. The problem is that according to IBindingList MSDN doc  "When you
call the AddNew method, you should raise a ListChanged event with the
ItemAdded enumeration carrying the appropriate index. The added row is in a
state where pressing the ESC on a DataGrid control can remove the new row.
Raising the ListChanged event with the ItemAdded enumeration a second time on
this row indicates that the item is now a row not in the "new" state"

In essence, the implementation of IBindingList should be statefull. When new
row is created ListChanged should fe fired twice - once with AddItem
parameter and second time with ether AddItem or RemoveItem depending of what
was the reult of item editing (EndEdit/CancelEdit)

If you use an example as is everything looks ok at a first glance, however
you will notice that the collection grows in size as you move focus away from
the grid and back. If you delete any of the newly created rows you may
encounter “Index Out Of Range” exception or other data binding issues

I have working sample now for anyone who's interested.

Boris
Sameer Khanna - 13 Sep 2004 06:55 GMT
I have similar type of problems when using MSDN example. It gives me
stackoverflow exception when assigning the datasource to my own
collection for the datagrid. Please send me some sample program at
sameer.khanna@ihealthcareinc.co.in. Thanks
Sameer Khanna - 13 Sep 2004 07:05 GMT
I have a similar type of problem but i got stackoverflow exception. i
have used the msdn example. please send me some good samples.
sameer.khanna@ihealthcareinc.co.in

thanks...sameer
Knut Vonheim - 01 Oct 2004 17:49 GMT
Boris,

I came across your message in my attempt to implement IBindingList.

I would love to see the sample code you have!

Do you implement Find and the other methods that typically throw an
exception?

TYIA,

Knut

> The implementation of IBindingList in this example is not entirely correct.
> That is probably why this example has been removed from the current version
[quoted text clipped - 18 lines]
>
> Boris
BorisDotNet - 06 Oct 2004 12:13 GMT
Hi Knut

We don't implement Find and others. Please send an e-mail to
boris@NOSPAM.qbf.com.au and i'll reply with the sample

cheers
boris

> Boris,
>
[quoted text clipped - 38 lines]
> >
> > Boris
Marcelo Duarte - 02 Oct 2004 23:33 GMT
BorisDotNet

You said :

"The implementation of IBindingList in this example is not entirely
correct.
That is probably why this example has been removed from the current
version
of MSDN. The problem is that according to IBindingList MSDN doc "When
you
call the AddNew method, you should raise a ListChanged event with the
ItemAdded enumeration carrying the appropriate index. The added row is
in a
state where pressing the ESC on a DataGrid control can remove the new
row.
Raising the ListChanged event with the ItemAdded enumeration a second
time on
this row indicates that the item is now a row not in the "new" state"

In essence, the implementation of IBindingList should be statefull. When
new
row is created ListChanged should fe fired twice - once with AddItem
parameter and second time with ether AddItem or RemoveItem depending of
what
was the reult of item editing (EndEdit/CancelEdit)

If you use an example as is everything looks ok at a first glance,
however
you will notice that the collection grows in size as you move focus away
from
the grid and back. If you delete any of the newly created rows you may
encounter ???Index Out Of Range??? exception or other data binding
issues

I have working sample now for anyone who's interested.

Boris".

Can you sendme a simple sample of class and collection where
IBindingList and IEditableObject and correctly implemented ?  You can
find me at M_Duarte at yahoo.com

Thanks ;-)

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.