Skip to content

Data Binding

Simon Mourier edited this page Feb 19, 2020 · 1 revision

CodeModeler-generated collections are designed to be bound to any .NET controls whether they are ASP.NET, Windows Forms, Windows Presentation Framework (WPF) or else. All those controls usually need is a specific .NET interface implementation and that's precisely why these collection classes implement so many of them: so, you can bind those collections to approximately anything in the .NET framework but also to all third-party controls supporting those standard interfaces. The following is a list of interfaces implemented by generated collection classes:

  • IEnumerable

  • IList

  • IList<T>

  • ICollection

  • ICollection<T>

  • IBindingList

  • IRaiseItemChangedEvents

  • INotifyPropertyChanged

  • INotifyCollectionChanged

  • ICancelAddNew

Depending on which control you want to bind your collection to, the fact that the collection implements one specific interface might become handy. For instance, the fact that the standard .NET ICancelAddNew interface is implemented, provides the developer transactional capability when adding a new item to the collection. However, the most important implementations are those of IBindingList and its generic implementation as well IBindingList<T>. By implementing this interface, all CodeModeler-generated collection classes provide features to support both complex and simple scenarios when binding them to a data source. Hence, data binding is fully supported by default by CodeModeler, and without any further modeling or configuration at design time.

For instance, we'll create a small Windows Forms application displaying all orders issued by a selected customer. Each order can contain one or more product:

Data Binding - Picture 275

On the client side, here's how to bind the complete list of customers to a ComboBox:

private void BindCustomers()
{
    customerComboBox.DisplayMember = "Name";
    customerComboBox.ValueMember = "Id";
    customerComboBox.DataSource = CustomerCollection.LoadAll();
}
Clone this wiki locally