Welcome to WindowsClient.net | Sign in | Join

Here are some frequently asked questions about Windows Forms and their answers.

Windows Forms FAQs

How do I get DataConnector to use an IList for a data source?

How do I get DataConnector to use an IList for a data source?

I'm trying to get a DataConnector component to recognize that my data source implements IList. According to the documentation, it should then use this implementation instead of its own list. I've tried inheriting from ArrayList and List<MyItem>, but the DataConnector wraps my list implementation inside its own list.

As a result, the Add and AddNew methods accept and return MyItemCollection objects, instead of the MyItem.

DataConnector always wraps the internal list. Calls to DataConnector.Add will call the wrapped list's Add method (which takes an object and returns an int - not quite what you said). If the wrapped list is an IBindingList, then calls to DataConnector.AddNew will call the wrapped list's AddNew. If the underlying list is not an IBindingList, then calls to DataConnector.AddNew will try to create a new instance of the item type contained in the underlying list (in your case, this would be MyItem) and add that item to the list. You can override the AddNew behavior of the DataConnector by overriding the AddingNew event on DataConnector.

Note: we've fixed a few bugs in this area in the latest Technology Preview (and DataConnector is now called BindingSource).