collection in BindingSource (synchronization)

L

lucassus

I've created simple list:
IList<XXX> _list = new List<XXX>();
_list.Add(..);
_list.Add(..);

and I've added this _list as data source of the ListBox control.
xxxBindingSource.DataSource = _list;
xxxListBox.DataSource = xxxBindingSource;

Afterwards I'm adding, removing, editing items by xxxBindingSource.
xxxBindingSource.Add(new XXX(...));
xxxBindingSource.Add(new XXX(...));
xxxBindingSource.RemoveCurrent(); ..etc.

The question is: how to synchronize xxxBindingSource with _list? For
instance after I had added item do xxxBindingSource it wasn't appeared
in _list collection (vice versa).

Thanks for help.
£ukasz
 
O

Otis Mukinfus

I've created simple list:
IList<XXX> _list = new List<XXX>();
_list.Add(..);
_list.Add(..);

and I've added this _list as data source of the ListBox control.
xxxBindingSource.DataSource = _list;
xxxListBox.DataSource = xxxBindingSource;

Afterwards I'm adding, removing, editing items by xxxBindingSource.
xxxBindingSource.Add(new XXX(...));
xxxBindingSource.Add(new XXX(...));
xxxBindingSource.RemoveCurrent(); ..etc.

The question is: how to synchronize xxxBindingSource with _list? For
instance after I had added item do xxxBindingSource it wasn't appeared
in _list collection (vice versa).

Thanks for help.
?ukasz

Have a look at BindingList<T>. It is designed especially for use with object
databinding. To use it you will need to also study up on IEditableObject and
INotifyPropertyChanged

A good book that explains these things is "DataBinding With Windows Forms 2.0"
by Noyes.

Good luck with your project,

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top