Upload
annabel-booth
View
222
Download
6
Embed Size (px)
Citation preview
Making the Most of WinForms 2.0Data Binding
Making the Most of WinForms 2.0Data Binding Rajiv SodhiRajiv Sodhi
Microsoft IndiaMicrosoft India
Agenda
Introduction to Data BindingIntroduction to Data Binding
New Objects and EnhancementsNew Objects and Enhancements
Master-Detail Data BindingMaster-Detail Data Binding
Object Data BindingObject Data Binding
Data Sources Window Drag and drop operations
Dragging/dropping tables from Data Dragging/dropping tables from Data Sources Window onto form will create Sources Window onto form will create instances of:instances of:
DataSet, TableAdapter, BindingSourceDataSet, TableAdapter, BindingSource
BindingNavigator with nav/add/delete/save BindingNavigator with nav/add/delete/save controlscontrols
Bound control(s)Bound control(s)
Use Data Sources window to Use Data Sources window to configure:configure:
Whether table will be edited with DataGridView Whether table will be edited with DataGridView or “Details” mode (individual controls)or “Details” mode (individual controls)
Mapping of detail control types to column data Mapping of detail control types to column data types (shortcut to Windows Forms types (shortcut to Windows Forms Designer/Data UI Customization node in Designer/Data UI Customization node in Options dialog)Options dialog)
Data Source Options
Database (DataSet)Database (DataSet)Any ADO.NET data Any ADO.NET data sourcesource
Web ServiceWeb ServiceBind to parameterized Bind to parameterized methods of a Web methods of a Web service, for select, service, for select, update, delete, and update, delete, and insert operationsinsert operations
ObjectObjectBind to instances of Bind to instances of classes and their classes and their properties (more later!)properties (more later!)
Smart Defaults
Control namesControl names
Label captionsLabel captions
Controlling through Caption property Controlling through Caption property of Column objects in typed DataSetsof Column objects in typed DataSets
Automatic addition of typed DataSets Automatic addition of typed DataSets and their DataTables to toolboxand their DataTables to toolbox
Data Sources Window - Drag and DropCompletely CustomizableChanging existing bindingChanging existing binding
Establishing list/lookup bindingEstablishing list/lookup bindingDisplayMemberDisplayMember
ValueMemberValueMember
SelectedValueSelectedValue
Use of SmartTagUse of SmartTag
More Smart DefaultsMore Smart Defaults
Drag and Drop Binding
Data Sources WindowData Sources Window
Drag and Drop Data BindingDrag and Drop Data Binding
Binding ControlsBinding Controls
Agenda
Introduction to Data BindingIntroduction to Data Binding
New Objects and EnhancementsNew Objects and Enhancements
Master-Detail Data BindingMaster-Detail Data Binding
Object Data BindingObject Data Binding
WinForms 2.0 Data BindingIntroduction to ObjectsTyped DataSetTyped DataSet
DataTable, TableAdapterDataTable, TableAdapter
BindingSourceBindingSource
[BindingNavigator][BindingNavigator]
Strongly-Typed DataSets
As beforeAs beforeConsist of DataTables, Relations, ConstraintsConsist of DataTables, Relations, Constraints
Drag/drop from Server Explorer is supportedDrag/drop from Server Explorer is supported
Based on XML schema and code-behind classBased on XML schema and code-behind class
Also consists of TableAdaptersAlso consists of TableAdaptersEncapsulate a DataAdapter and a ConnectionEncapsulate a DataAdapter and a Connection
Enhanced Typed Dataset DesignerEnhanced Typed Dataset DesignerInstead of XSD Designer earlierInstead of XSD Designer earlier
Partial class supportPartial class support
TableAdapters
Have Queries (methods for handling Have Queries (methods for handling selects, updates, inserts, deletes)selects, updates, inserts, deletes)
Queries exists as methods Queries exists as methods
Fully customizable and extendableFully customizable and extendable
Can be re-used across multiple formsCan be re-used across multiple forms
Have Connection propertyHave Connection propertyConnection string typically stored in Connection string typically stored in web/app.config; default value applied in web/app.config; default value applied in WinForms apps.WinForms apps.
BindingSource: Basics
Acts as “broker” between bound Acts as “broker” between bound controls and actual data sourcecontrols and actual data source
DataSource, DataMemberDataSource, DataMemberPoint to typed DataSet, DataTablePoint to typed DataSet, DataTable
AllowEdit, AllowNew, AllowRemove AllowEdit, AllowNew, AllowRemove
Filter, Sort propertiesFilter, Sort propertiesRun time: RemoveFilter, RemoveSort Run time: RemoveFilter, RemoveSort methodsmethods
BindingSourceRun time members
MovePrevious, MoveNext, MoveFirst, MovePrevious, MoveNext, MoveFirst, MoveLast, Position, Count properties MoveLast, Position, Count properties (handles all navigation)(handles all navigation)
AddNew, Insert(index, obj) methodsAddNew, Insert(index, obj) methods
RemoveCurrent , RemoveAt(index), RemoveCurrent , RemoveAt(index), Remove(obj)Remove(obj)
EndEdit, CancelEdit methodsEndEdit, CancelEdit methodsWorks with edits Works with edits andand inserts/new’s inserts/new’s
Use of most of these is optional due Use of most of these is optional due to…to…
BindingNavigator
UI provider that wraps navigation and UI provider that wraps navigation and maintenance functionality of maintenance functionality of BindingSource BindingSource NotNot like old VB data control like old VB data control
Has UI componentHas UI componentSpecialized toolstripSpecialized toolstrip
Has tray component tooHas tray component tooSelecting one will select bothSelecting one will select both
Members that associate ToolStrip Members that associate ToolStrip controls with specific actorscontrols with specific actors
DeleteItem = bindingNavigatorDeleteItem DeleteItem = bindingNavigatorDeleteItem (ToolStripButton)(ToolStripButton)
How It All Connects
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
Changes Changes control control
contents via contents via navigation, navigation,
maintenancemaintenanceBin
din
gN
avig
ato
rB
ind
ing
Nav
igat
or
BindingSourceBindingSource
DataSourceDataSource
Complex and Simple Binding Scenarios
Complex BindingComplex BindingDataGridView.DataSource = BindingSourceDataGridView.DataSource = BindingSource
SimpleBindingSimpleBindingTextBox.Text (and other controls/string-based TextBox.Text (and other controls/string-based properties) bound to member of BindingSourceproperties) bound to member of BindingSource
BindingNavigator.BindingSource = BindingNavigator.BindingSource = BindingSourceBindingSource
Introducing New Objects
Typed Dataset DesignerTyped Dataset Designer
Customizable Typed TableAdapterCustomizable Typed TableAdapter
Complex Binding ScenarioComplex Binding Scenario
Simple Binding ScenarioSimple Binding Scenario
Agenda
Introduction to Data BindingIntroduction to Data Binding
New Objects and EnhancementsNew Objects and Enhancements
Master-Detail Data BindingMaster-Detail Data Binding
Object Data BindingObject Data Binding
Master-Detail Scenarios
Binding to child rowsBinding to child rows
Use of Typed DataSet Use of Typed DataSet Relations/Foreign Keys as data Relations/Foreign Keys as data sourcessources
Precision drag & drop techniquesPrecision drag & drop techniquesDrop the child table, not the siblingDrop the child table, not the sibling
Master-Detail Binding
Agenda
Introduction to Data BindingIntroduction to Data Binding
New Objects and EnhancementsNew Objects and Enhancements
Master-Detail Data BindingMaster-Detail Data Binding
Object Data BindingObject Data Binding
Object Binding
Binding to single objectsBinding to single objects
Binding to BindingList<t>Binding to BindingList<t>
AllowNew scenarios: AddingNew AllowNew scenarios: AddingNew events on BindingSource and events on BindingSource and BindingList<t>BindingList<t>
Support for master-detail bindingSupport for master-detail binding
Object Binding
Resources
MSDN Smart Client Developer Center:http://msdn.microsoft.com/smartclient/Soup to Nuts: Build Windows Forms Applications with .NET(Webcasts and Virtual Labs):http://www.microsoft.com/events/series/windowsforms.mspx
WindowForms.NET Whidbey Page:http://windowsforms.net/Default.aspx?tabindex=5&tabid=60Improved Data Support Page:http://windowsforms.net/WhidbeyFeatures/default.aspx?PageID=2&ItemID=8&Cat=Runtime&tabindex=5
Newgroups:microsoft.public.dotnet.framework.windowsformscomp.lang.basic.visual.misc
© 2005 Microsoft Corporation. All rights reserved.This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.