I want to bind a list of business objects to a Winforms control (DataGridview, ComboBox, etc).
There are several ways to do this:
I can create wrapper classes for business objects and override their method implementation ToString. This will work well for ComboBox, ListBox methods Items.(Add|AddRange).
But this will not work for a DataGridView. It requires that an ObjectDataSource object configure columns in design mode.
As it should be ObjectDataSources (for DataGridViews) and wrapper classes, I decided to leave only one approach. ObjectDataSource
Now I have ObjectDataSources for data binding. When I use the wizard, it adds a property to the form, which I can use as follows:
MyObjectDataSoure.DataSource = list-of-entities;
This fills the base winforms control. But I can also assign a list of objects directly to the control data source and population properties. Same.
MyWinformsControl.DataSource = list-of-entities
Yes, now I am without ObjectDataSource events, but maybe there is something more general that I missed? Should I avoid listening to winforms events (the selection is changed, the user adds a row) and uses the object data of the data source?
What are the best practices for using object data sources and events?
Thank you in advance!
source
share