I want to bind list of business objects to Winforms control (DataGridview, ComboBox, e.t.c.).
There are several approaches to do that:
I can create wrapper classes for business objects and override their ToString
method implementation. That will work nice for ComboBox, ListBox Items.(Add|AddRange)
methods.
But this will not work for DataGridView. It requires ObjectDataSource to tune columns in a designer mode.
As there should be ObjectDataSources (for DataGridViews) and wrapper classes I decided to leave only one approach. The ObjectDataSource one.
Now I have ObjectDataSources for databinding. When I use wizard it adds property to a form that I can use like the following:
MyObjectDataSoure.DataSource = list-of-entities;
That populates underlying winforms control. But I can also assign list of entities directly to datasource property of control and population will be the same.
MyWinformsControl.DataSource = list-of-entities
Yes, now I am without ObjectDataSource events, but may be there is something more general I miss? Should I avoid listening to winforms events (selection changed, user adding a row) and use object data source ones?
What is the best practice to use object datasources and it's events ?
Thank you in advance!