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 / August 2007

Tip: Looking for answers? Try searching our database.

DataBoundSource has objects but DataBoundItem is empty in CellFormatting() event handler

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Steve - 01 Aug 2007 04:46 GMT
I must be missing something fundamental...

I have your basic DataGridView with its DataBoundSource set to a
collection object that is subclassed from BindingList<T>.  Objects are
added to the BindingList<T> collection. With the debugger I can see
that the DataGridView.DataBoundSource shows a non-zero count, and the
objects present have correct data.  Unfortunately, when the object
data is accessed for display through the bound properties, the object
data is all default 0's and empty strings.  The correct number of rows
is displayed.  It's just all wrong data!

To debug further, I added a CellFormatting() event handler.  Whenever
it gets called, the
DataGridView.Rows[e.RowIndex].DataBoundItem is that same empty default
object instance.

FWIW: The objects are added to the DataBoundSource from another thread
going through an Invoke().  I don't see this as a real problem as the
objects are correctly shown browsing through the DataBoundSource with
the debugger.

I've added calls to SuspendBinding and ResumeBinding before and after
adding the object to the BindingList<T> collection without any effect.

The DataGridView is read-only, i.e.:

   DataGridView.AllowUserToAddRows = false;
   DataGridView.AllowUserToDeleteRows = false;

because I saw mention of an empty row AllowUserToAddRows is true.

I don't have a "copy constructor", but I do have ICloneable
implemented on the <T> class used to define the BindingList.  It never
gets called.

So where and why is there an empty object instance being used for
displaying each row?

Thank you,
Steve
Steve - 01 Aug 2007 05:50 GMT
Never mind.  The old "add a reference to a working object to the
collection rather than a <b>Clone()</b> of the working object" trick.

Sorry for the wasted bandwidth...

Steve

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.