Data Binding In Depth
-
Upload
eyal-vardi -
Category
Technology
-
view
3.919 -
download
6
description
Transcript of Data Binding In Depth
![Page 1: Data Binding In Depth](https://reader033.fdocuments.net/reader033/viewer/2022052315/548783e0b4af9f5f388b56fb/html5/thumbnails/1.jpg)
Data Binding in DepthDEV 419 Level 400
Data Binding in DepthDEV 419 Level 400
Eyal VardiEyal VardiCEO Experts4DCEO Experts4DMicrosoft VSTO MVPMicrosoft VSTO MVPblog: www.eVardi.comblog: www.eVardi.com
![Page 2: Data Binding In Depth](https://reader033.fdocuments.net/reader033/viewer/2022052315/548783e0b4af9f5f388b56fb/html5/thumbnails/2.jpg)
AgendaAgenda
Data Binding OverviewData Binding Overview
BindingSource ClassBindingSource Class
Data Source & InterfacesData Source & Interfaces
Binding Class ImprovementBinding Class Improvement
![Page 3: Data Binding In Depth](https://reader033.fdocuments.net/reader033/viewer/2022052315/548783e0b4af9f5f388b56fb/html5/thumbnails/3.jpg)
Application Architecture Application Architecture
BindingBinding
![Page 4: Data Binding In Depth](https://reader033.fdocuments.net/reader033/viewer/2022052315/548783e0b4af9f5f388b56fb/html5/thumbnails/4.jpg)
What Can we Bind?What Can we Bind?
One WayOne Way
Two WayTwo Way
.NET Controls.NET ControlsSimple BindingSimple Binding
.NET Controls.NET ControlsComplex BindingComplex Binding
Data ConsumersData ConsumersData ProvidersData Providers
ObjectObject
ArrayListArrayList
DataSetDataSet
Custom CollectionCustom Collection
Config FileConfig File
You can You can onlyonly bind to the public properties bind to the public properties
![Page 5: Data Binding In Depth](https://reader033.fdocuments.net/reader033/viewer/2022052315/548783e0b4af9f5f388b56fb/html5/thumbnails/5.jpg)
SimpleSimple
BindingBindingLabel, TextBox, Label, TextBox,
PictureBox, PictureBox, DateTimePickerDateTimePicker
Complex Complex BindingBinding
DataGrid, DataGrid, ComboBox, ComboBox,
ListBoxListBox
![Page 6: Data Binding In Depth](https://reader033.fdocuments.net/reader033/viewer/2022052315/548783e0b4af9f5f388b56fb/html5/thumbnails/6.jpg)
Data Binding GoalsData Binding Goals
Run-Time:Run-Time:BindingBinding Data to Controls Data to Controls
SynchronizeSynchronize the data between the controls the data between the controls
FormattingFormatting and and ParsingParsing the data the data
FilterFilter, , Sort Sort andand Search Search the data the data
Design-Time:Design-Time:Simple and fast to implementSimple and fast to implement
![Page 7: Data Binding In Depth](https://reader033.fdocuments.net/reader033/viewer/2022052315/548783e0b4af9f5f388b56fb/html5/thumbnails/7.jpg)
![Page 8: Data Binding In Depth](https://reader033.fdocuments.net/reader033/viewer/2022052315/548783e0b4af9f5f388b56fb/html5/thumbnails/8.jpg)
Data TemplatesData Templates
Data TemplateData Template
class Addressclass 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 ControlUser Control
![Page 9: Data Binding In Depth](https://reader033.fdocuments.net/reader033/viewer/2022052315/548783e0b4af9f5f388b56fb/html5/thumbnails/9.jpg)
Customize Data Source WinCustomize Data Source Win
Need to implement one of the following Need to implement one of the following data binding attributes:data binding attributes:
DefaultDefaultBindingPropertyAttributeBindingPropertyAttribute
ComplexComplexBindingPropertiesAttributeBindingPropertiesAttribute
LookupLookupBindingPropertiesAttributeBindingPropertiesAttribute
![Page 10: Data Binding In Depth](https://reader033.fdocuments.net/reader033/viewer/2022052315/548783e0b4af9f5f388b56fb/html5/thumbnails/10.jpg)
Data TemplateData Template
![Page 11: Data Binding In Depth](https://reader033.fdocuments.net/reader033/viewer/2022052315/548783e0b4af9f5f388b56fb/html5/thumbnails/11.jpg)
Binding SourceBinding Source
![Page 12: Data Binding In Depth](https://reader033.fdocuments.net/reader033/viewer/2022052315/548783e0b4af9f5f388b56fb/html5/thumbnails/12.jpg)
The Binding FlowThe Binding Flow
Bin
din
gS
ou
rce
Bin
din
gS
ou
rce
Dat
aSet
Dat
aSet
Dat
aTab
leD
ataT
able
DataSourceDataSource
DataMemberDataMember
SimpleSimpleControlControl
ComplexComplexControlControl
Co
lum
nC
olu
mnDataBindingDataBinding
PropertyProperty
DataSourceDataSource
BindingSourceBindingSource
* *Don’t forget to add default constructorDon’t forget to add default constructor
![Page 13: Data Binding In Depth](https://reader033.fdocuments.net/reader033/viewer/2022052315/548783e0b4af9f5f388b56fb/html5/thumbnails/13.jpg)
Closer look on BindingSourceCloser look on BindingSource
ControlControl BindingSourceBindingSource
Simple BindingSimple Binding
Complex BindingComplex Binding
CurrencyManagerCurrencyManager
ControlControl
Data SourceData Source
BindingBinding
Binding
Binding
BindingContexBindingContexBindingContexBindingContex
![Page 14: Data Binding In Depth](https://reader033.fdocuments.net/reader033/viewer/2022052315/548783e0b4af9f5f388b56fb/html5/thumbnails/14.jpg)
BindingSource ClassBindingSource Class(Binding Contex)(Binding Contex)
![Page 15: Data Binding In Depth](https://reader033.fdocuments.net/reader033/viewer/2022052315/548783e0b4af9f5f388b56fb/html5/thumbnails/15.jpg)
BindingSource.DataSource =BindingSource.DataSource =
ArrayArray => => NoNo Add & Remove Add & Remove
List<> List<> => Add & Remove=> Add & Remove
TypOf TypOf => Add & Remove=> Add & Remove
new Object()new Object() => Add & Remove=> Add & Remove
**BindingList<> BindingList<> => Add & Remove=> Add & Remove
DataView DataView => Add, Remove, => Add, Remove, Sort, Search, Sort, Search,
FilterFilter** Dervied Class can SupportDervied Class can Support::
Sort, Search and FilterSort, Search and Filter
?
![Page 16: Data Binding In Depth](https://reader033.fdocuments.net/reader033/viewer/2022052315/548783e0b4af9f5f388b56fb/html5/thumbnails/16.jpg)
BindingSource ClassBindingSource Class(Sort, Find & Filter)(Sort, Find & Filter)
![Page 17: Data Binding In Depth](https://reader033.fdocuments.net/reader033/viewer/2022052315/548783e0b4af9f5f388b56fb/html5/thumbnails/17.jpg)
Data Source & InterfacesData Source & Interfaces
![Page 18: Data Binding In Depth](https://reader033.fdocuments.net/reader033/viewer/2022052315/548783e0b4af9f5f388b56fb/html5/thumbnails/18.jpg)
IEnumerable ICollection IList IBindingListIEnumerable ICollection IList IBindingList
.NET 1.x Interfaces.NET 1.x Interfaces
![Page 19: Data Binding In Depth](https://reader033.fdocuments.net/reader033/viewer/2022052315/548783e0b4af9f5f388b56fb/html5/thumbnails/19.jpg)
.NET 2.0 New Interface.NET 2.0 New Interface
![Page 20: Data Binding In Depth](https://reader033.fdocuments.net/reader033/viewer/2022052315/548783e0b4af9f5f388b56fb/html5/thumbnails/20.jpg)
Build Custom Data SourceBuild Custom Data Source
1.1. Interfaces should be implemented Interfaces should be implemented in your custom collectionin your custom collection
IBindingListViewIBindingListView SortSort
Advanced SortAdvanced Sort
FilterFilter
SearchSearch
![Page 21: Data Binding In Depth](https://reader033.fdocuments.net/reader033/viewer/2022052315/548783e0b4af9f5f388b56fb/html5/thumbnails/21.jpg)
Recipe…Recipe…
1)1) Inherit BindingList<>Inherit BindingList<>
2)2) Add Add sortsort and and searchsearch capabilitycapability
3)3) Implement Implement IBindingListView for IBindingListView for getting getting advance sortadvance sort and and filterfilter capability capability
![Page 22: Data Binding In Depth](https://reader033.fdocuments.net/reader033/viewer/2022052315/548783e0b4af9f5f388b56fb/html5/thumbnails/22.jpg)
BindingListView<T>BindingListView<T>
![Page 23: Data Binding In Depth](https://reader033.fdocuments.net/reader033/viewer/2022052315/548783e0b4af9f5f388b56fb/html5/thumbnails/23.jpg)
Build Custom Data SourceBuild Custom Data Source
2.2. Interfaces should be implemented Interfaces should be implemented in your custom typein your custom type
INotifyPropertyChangedINotifyPropertyChanged
IEditableObjectIEditableObject
IDataErrorInfoIDataErrorInfo
![Page 24: Data Binding In Depth](https://reader033.fdocuments.net/reader033/viewer/2022052315/548783e0b4af9f5f388b56fb/html5/thumbnails/24.jpg)
INotifyPropertyChangedINotifyPropertyChanged
IEditableObjectIEditableObject
IDataErrorInfoIDataErrorInfo
![Page 25: Data Binding In Depth](https://reader033.fdocuments.net/reader033/viewer/2022052315/548783e0b4af9f5f388b56fb/html5/thumbnails/25.jpg)
New Feature in Binding ClassNew Feature in Binding Class
Update modeUpdate mode
Formatting dataFormatting data
Null ValueNull Value
Error notificationError notification
![Page 26: Data Binding In Depth](https://reader033.fdocuments.net/reader033/viewer/2022052315/548783e0b4af9f5f388b56fb/html5/thumbnails/26.jpg)
New Feature in New Feature in Binding ClassBinding Class
![Page 27: Data Binding In Depth](https://reader033.fdocuments.net/reader033/viewer/2022052315/548783e0b4af9f5f388b56fb/html5/thumbnails/27.jpg)
Custom Formatting & ParsingCustom Formatting & Parsing
We use theWe use the BindingBinding class events: class events:
FormatFormat, , raised when data is pushed from raised when data is pushed from the data source into the control the data source into the control
ParseParse, , raised when data is pushed from the raised when data is pushed from the control into the data source control into the data source
ControlControl DataDataSourceSource
Parse EventParse Event
Format EventFormat Event
BindingBinding
![Page 28: Data Binding In Depth](https://reader033.fdocuments.net/reader033/viewer/2022052315/548783e0b4af9f5f388b56fb/html5/thumbnails/28.jpg)
Type ConversionType Conversion
Custom data type to string, can be done:Custom data type to string, can be done:
Override the Override the ToString()ToString()
Use the Binding Use the Binding FormatFormat event event
Write custom class for conversionWrite custom class for conversion
String to custom data type, can be done:String to custom data type, can be done:
Use the Binding Use the Binding ParseParse event event
Write custom class for conversionWrite custom class for conversion
![Page 29: Data Binding In Depth](https://reader033.fdocuments.net/reader033/viewer/2022052315/548783e0b4af9f5f388b56fb/html5/thumbnails/29.jpg)
Custom Formatting & Custom Formatting & Type ConverterType Converter
![Page 30: Data Binding In Depth](https://reader033.fdocuments.net/reader033/viewer/2022052315/548783e0b4af9f5f388b56fb/html5/thumbnails/30.jpg)
DataSet Can’t DataSet Can’t Solve All Solve All
your Problemsyour Problems
![Page 31: Data Binding In Depth](https://reader033.fdocuments.net/reader033/viewer/2022052315/548783e0b4af9f5f388b56fb/html5/thumbnails/31.jpg)
BooksBooks
www.www.izzyizzybooks.combooks.com
![Page 32: Data Binding In Depth](https://reader033.fdocuments.net/reader033/viewer/2022052315/548783e0b4af9f5f388b56fb/html5/thumbnails/32.jpg)
![Page 33: Data Binding In Depth](https://reader033.fdocuments.net/reader033/viewer/2022052315/548783e0b4af9f5f388b56fb/html5/thumbnails/33.jpg)
New York! New York!New York! New York!
איך ממלאים משוב?איך ממלאים משוב? בסוף כל יום בסוף כל יום emailemailב - ב -
Beat CenterBeat Centerב -ב -
מה מקבלים?מה מקבלים?Feel The BeatFeel The Beatחולצת חולצת
השתתפות בהגרלת כרטיסי טיסההשתתפות בהגרלת כרטיסי טיסה)לממלאים משוב לכל )לממלאים משוב לכל ועוד... ועוד...i-matei-mateמכשירי מכשירי
DEV419DEV419יום(יום(
![Page 34: Data Binding In Depth](https://reader033.fdocuments.net/reader033/viewer/2022052315/548783e0b4af9f5f388b56fb/html5/thumbnails/34.jpg)
Your potential. Our passion. TM