Data Binding in Depth DEV 419 Level 400
-
Upload
cara-vasquez -
Category
Documents
-
view
43 -
download
1
description
Transcript of Data Binding in Depth DEV 419 Level 400
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
AgendaAgenda
Data Binding OverviewData Binding Overview
BindingSource ClassBindingSource Class
Data Source & InterfacesData Source & Interfaces
Binding Class ImprovementBinding Class Improvement
Application Architecture Application Architecture
BindingBinding
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
SimpleSimple
BindingBindingLabel, TextBox, Label, TextBox,
PictureBox, PictureBox, DateTimePickerDateTimePicker
Complex Complex BindingBinding
DataGrid, DataGrid, ComboBox, ComboBox,
ListBoxListBox
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
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
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
Data TemplateData Template
Binding SourceBinding Source
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
Closer look on BindingSourceCloser look on BindingSource
ControlControl BindingSourceBindingSource
Simple BindingSimple Binding
Complex BindingComplex Binding
CurrencyManagerCurrencyManager
ControlControl
Data SourceData Source
BindingBinding
Binding
Binding
BindingContexBindingContexBindingContexBindingContex
BindingSource ClassBindingSource Class(Binding Contex)(Binding Contex)
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
?
BindingSource ClassBindingSource Class(Sort, Find & Filter)(Sort, Find & Filter)
Data Source & InterfacesData Source & Interfaces
IEnumerable ICollection IList IBindingListIEnumerable ICollection IList IBindingList
.NET 1.x Interfaces.NET 1.x Interfaces
.NET 2.0 New Interface.NET 2.0 New Interface
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
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
BindingListView<T>BindingListView<T>
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
INotifyPropertyChangedINotifyPropertyChanged
IEditableObjectIEditableObject
IDataErrorInfoIDataErrorInfo
New Feature in Binding ClassNew Feature in Binding Class
Update modeUpdate mode
Formatting dataFormatting data
Null ValueNull Value
Error notificationError notification
New Feature in New Feature in Binding ClassBinding Class
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
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
Custom Formatting & Custom Formatting & Type ConverterType Converter
DataSet Can’t DataSet Can’t Solve All Solve All
your Problemsyour Problems
BooksBooks
www.www.izzyizzybooks.combooks.com
New York! New York!New York! New York!
איך ממלאים משוב?איך ממלאים משוב? בסוף כל יום בסוף כל יום emailemailב - ב -
Beat CenterBeat Centerב -ב -
מה מקבלים?מה מקבלים?Feel The BeatFeel The Beatחולצת חולצת
השתתפות בהגרלת כרטיסי טיסההשתתפות בהגרלת כרטיסי טיסה)לממלאים משוב לכל )לממלאים משוב לכל ועוד... ועוד...i-matei-mateמכשירי מכשירי
DEV419DEV419יום(יום(
Your potential. Our passion. TM