data binding in depth dev 419 level 400 eyal vardi ceo experts4d microsoft vsto mvp blog:

34
Data Binding in Depth DEV 419 Level 400 Eyal Vardi Eyal Vardi CEO Experts4D CEO Experts4D Microsoft VSTO MVP Microsoft VSTO MVP blog: www.eVardi.com blog: www.eVardi.com

Upload: isaac-simon

Post on 02-Jan-2016

215 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Data Binding in Depth DEV 419 Level 400 Eyal Vardi CEO Experts4D Microsoft VSTO MVP blog:

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 DEV 419 Level 400 Eyal Vardi CEO Experts4D Microsoft VSTO MVP blog:

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 DEV 419 Level 400 Eyal Vardi CEO Experts4D Microsoft VSTO MVP blog:

Application Architecture Application Architecture

BindingBinding

Page 4: Data Binding in Depth DEV 419 Level 400 Eyal Vardi CEO Experts4D Microsoft VSTO MVP blog:

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 DEV 419 Level 400 Eyal Vardi CEO Experts4D Microsoft VSTO MVP blog:

SimpleSimple

BindingBindingLabel, TextBox, Label, TextBox,

PictureBox, PictureBox, DateTimePickerDateTimePicker

Complex Complex BindingBinding

DataGrid, DataGrid, ComboBox, ComboBox,

ListBoxListBox

Page 6: Data Binding in Depth DEV 419 Level 400 Eyal Vardi CEO Experts4D Microsoft VSTO MVP blog:

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 DEV 419 Level 400 Eyal Vardi CEO Experts4D Microsoft VSTO MVP blog:
Page 8: Data Binding in Depth DEV 419 Level 400 Eyal Vardi CEO Experts4D Microsoft VSTO MVP blog:

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 DEV 419 Level 400 Eyal Vardi CEO Experts4D Microsoft VSTO MVP blog:

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 DEV 419 Level 400 Eyal Vardi CEO Experts4D Microsoft VSTO MVP blog:

Data TemplateData Template

Page 11: Data Binding in Depth DEV 419 Level 400 Eyal Vardi CEO Experts4D Microsoft VSTO MVP blog:

Binding SourceBinding Source

Page 12: Data Binding in Depth DEV 419 Level 400 Eyal Vardi CEO Experts4D Microsoft VSTO MVP blog:

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 DEV 419 Level 400 Eyal Vardi CEO Experts4D Microsoft VSTO MVP blog:

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 DEV 419 Level 400 Eyal Vardi CEO Experts4D Microsoft VSTO MVP blog:

BindingSource ClassBindingSource Class(Binding Contex)(Binding Contex)

Page 15: Data Binding in Depth DEV 419 Level 400 Eyal Vardi CEO Experts4D Microsoft VSTO MVP blog:

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 DEV 419 Level 400 Eyal Vardi CEO Experts4D Microsoft VSTO MVP blog:

BindingSource ClassBindingSource Class(Sort, Find & Filter)(Sort, Find & Filter)

Page 17: Data Binding in Depth DEV 419 Level 400 Eyal Vardi CEO Experts4D Microsoft VSTO MVP blog:

Data Source & InterfacesData Source & Interfaces

Page 18: Data Binding in Depth DEV 419 Level 400 Eyal Vardi CEO Experts4D Microsoft VSTO MVP blog:

IEnumerable ICollection IList IBindingListIEnumerable ICollection IList IBindingList

.NET 1.x Interfaces.NET 1.x Interfaces

Page 19: Data Binding in Depth DEV 419 Level 400 Eyal Vardi CEO Experts4D Microsoft VSTO MVP blog:

.NET 2.0 New Interface.NET 2.0 New Interface

Page 20: Data Binding in Depth DEV 419 Level 400 Eyal Vardi CEO Experts4D Microsoft VSTO MVP blog:

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 DEV 419 Level 400 Eyal Vardi CEO Experts4D Microsoft VSTO MVP blog:

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 DEV 419 Level 400 Eyal Vardi CEO Experts4D Microsoft VSTO MVP blog:

BindingListView<T>BindingListView<T>

Page 23: Data Binding in Depth DEV 419 Level 400 Eyal Vardi CEO Experts4D Microsoft VSTO MVP blog:

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 DEV 419 Level 400 Eyal Vardi CEO Experts4D Microsoft VSTO MVP blog:

INotifyPropertyChangedINotifyPropertyChanged

IEditableObjectIEditableObject

IDataErrorInfoIDataErrorInfo

Page 25: Data Binding in Depth DEV 419 Level 400 Eyal Vardi CEO Experts4D Microsoft VSTO MVP blog:

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 DEV 419 Level 400 Eyal Vardi CEO Experts4D Microsoft VSTO MVP blog:

New Feature in New Feature in Binding ClassBinding Class

Page 27: Data Binding in Depth DEV 419 Level 400 Eyal Vardi CEO Experts4D Microsoft VSTO MVP blog:

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 DEV 419 Level 400 Eyal Vardi CEO Experts4D Microsoft VSTO MVP blog:

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 DEV 419 Level 400 Eyal Vardi CEO Experts4D Microsoft VSTO MVP blog:

Custom Formatting & Custom Formatting & Type ConverterType Converter

Page 30: Data Binding in Depth DEV 419 Level 400 Eyal Vardi CEO Experts4D Microsoft VSTO MVP blog:

DataSet Can’t DataSet Can’t Solve All Solve All

your Problemsyour Problems

Page 31: Data Binding in Depth DEV 419 Level 400 Eyal Vardi CEO Experts4D Microsoft VSTO MVP blog:

BooksBooks

www.www.izzyizzybooks.combooks.com

Page 32: Data Binding in Depth DEV 419 Level 400 Eyal Vardi CEO Experts4D Microsoft VSTO MVP blog:
Page 33: Data Binding in Depth DEV 419 Level 400 Eyal Vardi CEO Experts4D Microsoft VSTO MVP blog:

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 DEV 419 Level 400 Eyal Vardi CEO Experts4D Microsoft VSTO MVP blog:

Your potential. Our passion. TM