Binding DataGridView column to a Child object property

Binding DataGridView column to a Child object property

Old forum URL: forums.lhotka.net/forums/t/5143.aspx


sroberts posted on Wednesday, July 23, 2008

I've run into a problem that I fear may be a limitation of the current Microsoft DataGridView control.

The limitation being that I can't seem to bind a DataGridViewComboBoxColumn to the property of a child object exposed through a parent object.

To further clarify, I have the DataGridView bound to a Binding Source that is bound to a parent object called Association.

Each Association object exposes various standard get/set type properties of the base types (int, string etc) and the Data Grid works fine for these, however one of the properies is a child object called Role.

The Role object is used to represent an ID selectable property, that also provides a ToString equivalent and also a function to provide the lookup list of values to the UI.

(just a quick note why I'm using a child object here...I prefer to handle the provision of providing the correct lookup list in the Business Object as opposed to placing this code in all the UI's that bind to it. Therefore my role object wraps up an ID property get/set accessor, a ToString() function and a LookupList() function that is used by the UI's to bind a combobox to)

I've bound the DataPropertyName of the colum to Role.ID, which via the binding source on the parant object, I was hoping would resolve down through the child (Role) to it's ID property.

The combobox column binds the list of values using LookupList and the combo box populates with the correct list of values, and when I select a value the text appears in the grid, however I have a breakpoint on the Set of the ID field within the Role object and this never fires, so I can tell the ID of the selected combobox entry is not getting pushed down to the object.

I've done some searching on the internet and found various posts that refer to what I need to do, but the workarounds seem to involve hacks that I don't think will work for CSLA

(http://www.developer-corner.com/Resources/KnowledgeBase/tabid/118/articleType/ArticleView/articleId/28/DataGridView-how-to-bind-nested-objects.aspx)

Or a posting back in 2006 from Mark Rideout (the then 'DataGridView Program Manager') that "...The DataGridView does not support databinding to child properties like you want. You'll need to resort to using the toString workaround..." (http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=94640&SiteID=1)

Has anyone else had to tackle this with CSLA and succeeded ?

Regards,

S.Roberts

 

Copyright (c) Marimer LLC