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
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
Don't see what you're looking for? Try a search.
|