Data Binding in Depth DEV 419 Level 400 Eyal Vardi CEO Experts4D Microsoft VSTO MVP blog:
Agenda Data Binding Overview BindingSource Class Data Source & Interfaces Binding Class Improvement
Application Architecture Binding
What Can we Bind? One Way Two Way.NET Controls Simple Binding.NET Controls Complex Binding Data Consumers Data Providers Object ArrayList DataSet Custom Collection Config File You can only bind to the public properties
SimpleBinding Label, TextBox, PictureBox, DateTimePicker ComplexBinding DataGrid, ComboBox, ListBox
Data Binding Goals Run-Time: Binding Data to Controls Synchronize the data between the controls Formatting and Parsing the data Filter, Sort and Search the data Design-Time: Simple and fast to implement
Data Templates Data Template class Address { string Address {get;set} string Address {get;set} string City {get;set} string City {get;set} string COuntry {get;set} string COuntry {get;set} string PostalCode {get;set} string PostalCode {get;set}} User Control
Customize Data Source Win Need to implement one of the following data binding attributes: DefaultBindingPropertyAttribute ComplexBindingPropertiesAttribute LookupBindingPropertiesAttribute
Data Template
Binding Source
The Binding Flow BindingSource DataSet DataTable DataSource DataMember Simple Control Complex Control Column DataBinding Property DataSource BindingSource * Don’t forget to add default constructor
Closer look on BindingSource Control BindingSource Simple Binding Complex Binding CurrencyManager Control Data Source Binding Binding BindingContexBindingContex
BindingSource Class (Binding Contex)
BindingSource.DataSource = Array=> No Add & Remove List<> => Add & Remove TypOf => Add & Remove new Object()=> Add & Remove *BindingList<> => Add & Remove DataView => Add, Remove, Sort, Search, Filter * Dervied Class can Support: Sort, Search and Filter ?
BindingSource Class (Sort, Find & Filter)
Data Source & Interfaces
IEnumerable ICollection IList IBindingList.NET 1.x Interfaces
.NET 2.0 New Interface
Build Custom Data Source 1.Interfaces should be implemented in your custom collection IBindingListView Sort Sort Advanced Sort Advanced Sort Filter Filter Search Search
Recipe… 1)Inherit BindingList<> 2)Add sort and search capability 3)Implement IBindingListView for getting advance sort and filter capability
.NET 1.x Interfaces
BindingListView<T>
Build Custom Data Source 2.Interfaces should be implemented in your custom type INotifyPropertyChangedIEditableObjectIDataErrorInfo
INotifyPropertyChanged INotifyPropertyChanged IEditableObject IEditableObject IDataErrorInfo IDataErrorInfo
New Feature in Binding Class Update mode Formatting data Null Value Error notification
New Feature in Binding Class
Custom Formatting & Parsing We use the Binding class events: Format, raised when data is pushed from the data source into the control Parse, raised when data is pushed from the control into the data source ControlDataSource Parse Event Format Event Binding
Type Conversion Custom data type to string, can be done: Custom data type to string, can be done: Override the ToString() Override the ToString() Use the Binding Format event Use the Binding Format event Write custom class for conversion Write custom class for conversion String to custom data type, can be done: String to custom data type, can be done: Use the Binding Parse event Use the Binding Parse event Write custom class for conversion Write custom class for conversion
Custom Formatting & Type Converter
DataSet Can’t Solve All your Problems
Books
New York! איך ממלאים משוב? ב - בסוף כל יום ב -Beat Center מה מקבלים? חולצת Feel The Beat השתתפות בהגרלת כרטיסי טיסה מכשירי i-mate ועוד... (לממלאים משוב לכל יום) DEV419
Your potential. Our passion. TM