340 likes | 469 Views
Eyal Vardi CEO Experts4D Microsoft VSTO MVP blog: www.eVardi.com. Data Binding in Depth DEV 419 Level 400. Agenda. Data Binding Overview BindingSource Class Data Source & Interfaces Binding Class Improvement. Binding. Application Architecture. What Can we Bind?. Data Consumers.
E N D
Eyal Vardi CEO Experts4DMicrosoft VSTO MVPblog: www.eVardi.com Data Binding in DepthDEV 419 Level 400
Agenda • Data Binding Overview • BindingSource Class • Data Source & Interfaces • Binding Class Improvement
Binding Application Architecture
What Can we Bind? Data Consumers Data Providers Object You can only bind to the public properties One Way .NET ControlsSimple Binding ArrayList DataSet .NET ControlsComplex Binding Custom Collection Two Way Config File
Simple Binding Label, TextBox, PictureBox, DateTimePicker Complex Binding 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 class Address { string Address {get;set} string City {get;set} string COuntry {get;set} string PostalCode {get;set} } User Control Data Template
Customize Data Source Win • Need to implement one of the following data binding attributes: • DefaultBindingPropertyAttribute • ComplexBindingPropertiesAttribute • LookupBindingPropertiesAttribute
SimpleControl ComplexControl DataSource DataMember Property DataBinding Column DataTable DataSource BindingSource DataSet BindingSource The Binding Flow * Don’t forget to add default constructor
Closer look on BindingSource BindingSource Control Data Source Simple Binding Binding CurrencyManager Control Binding Complex Binding BindingContex
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)
IEnumerable ICollection IList IBindingList .NET 1.x Interfaces
Build Custom Data Source • Interfaces should be implemented in your custom collection • IBindingListView • Sort • Advanced Sort • Filter • Search
Recipe… Inherit BindingList<> Add sort and search capability Implement IBindingListView for getting advance sort and filter capability
Build Custom Data Source • Interfaces should be implemented in your custom type • INotifyPropertyChanged • IEditableObject • IDataErrorInfo
INotifyPropertyChanged • IEditableObject • IDataErrorInfo
New Feature in Binding Class • Update mode • Formatting data • Null Value • Error notification
New Feature in Binding Class
Custom Formatting & Parsing • We use theBinding 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 Control Data Source Binding Parse Event Format Event
Type Conversion • Custom data type to string, can be done: • Override the ToString() • Use the Binding Format event • Write custom class for conversion • String to custom data type, can be done: • Use the Binding Parse event • Write custom class for conversion
Books www.izzybooks.com
איך ממלאים משוב? ב - email בסוף כל יום ב -Beat Center מה מקבלים? חולצת Feel The Beat השתתפות בהגרלת כרטיסי טיסה מכשירי i-mate ועוד...(לממלאים משוב לכל יום) New York! New York! DEV419