DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Tue, 31 Jul 2007 20:46:45 -0700,    posted on: microsoft.public.dotnet.framework.windowsforms.databinding        back       

Thread Index
  1    Steve
          2    Steve


DataBoundSource has objects but DataBoundItem is empty in CellFormatting() event handler   
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
Date:Tue, 31 Jul 2007 20:46:45 -0700   Author:  

Re: DataBoundSource has objects but DataBoundItem is empty in CellFormatting() event handler   
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
Date:Tue, 31 Jul 2007 21:50:50 -0700   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us