Is it possible to bind a complex object tree to a BindingSource?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi,
I have a project that uses an object list as its primary data source. Each object contains "name" and various other properties as well as a collection (List) of property objects. Property objects each contain a value property and various others.
What I am trying to do is show that data in a DataGridView via a BindingSource. I have achieved this so far by writing a "ToTable" method that flattens this structure to a DataTable using the Name of the object and the value of the child-property object
as the fields of the table.
This is rather cumbersome because every time I update the structure via the grid I need to find the corresponding object in the tree before I can run the update. Id like to be able to access the objects directly.
The perfect scenario would be some way to bind each object to a cell, so I can go direct to the object via cell coordinates. This is harder than I thought mainly due to the way I filter the grid, cell coordinates change while the objects stay where they
were in the tree (the object tree does not filter, but the visible grid does).
Also the filter requires the use of a BindingSource.
I could inherit from DataGridViewCell to give a field that holds the physical object, but Id still need to run the ToTable method to generate the cells via BindingSource binding to datagrid... Im also not sure how the grid will behave once filtered,
does the filter mechanic hide the cells or simple delete them and move up the data? If the cells are deleted the objects could be mis-represented after filtering.
Im fairly new to this level of coding so any thoughts would be appreciated. Thanks!

View the full article
 
Back
Top