DEV397 Windows Forms Databinding Mike Henderlight Program Manager Windows Forms Microsoft Corporation.

Slides:



Advertisements
Similar presentations
DEV351 ADO.NET Performance Pablo Castro Program Manager – ADO.NET Team Microsoft Corporation.
Advertisements

WEB401 Security Practices for Web Services (Part 2) Keith Ballinger Program Manager XML Messaging Microsoft Corporation.
DEV392: Extending SharePoint Products And Technologies Through Web Parts And ASP.NET Clint Covington, Program Manager Data And Developer Services - Office.
ASP.NET Data Binding. Slide 2 Lecture Overview Understanding the ASP.NET data binding model.
Chapter 12: ADO.NET and ASP.NET Programming with Microsoft Visual Basic.NET, Second Edition.
Introduction to ADO.Net, VB.Net Database Tools and Data Binding ISYS 512.
Windows Forms in Visual Studio 2005: An in-depth look at key features Name: Mike Henderlight Title: Program Manager.
VB.NET Database Access ISYS 812. Microsoft Universal Data Access ODBC: Open Database Connectivity –A driver manager –Used for relational databases OLE.
1 Pertemuan 09 Database Matakuliah: D0524 / Algoritma dan Pemrograman Komputer Tahun: 2005 Versi:
Introduction to ADO.Net and Visual Studio Database Tools ISYS 512.
Introduction to ADO.Net, VB.Net Database Tools and Data Binding ISYS 512.
Visual Studio 2005 C# IDE Enhancements Luca Bolognese C# Program Manager Microsoft Corporation.
Introduction to ADO.Net, VB.Net Database Tools and Data Binding ISYS 512.
Sunday Business Systems Using Access More Efficiently Tips and tricks to improve productivity.
OFC 322 Building Office Research Web Services: Exposing Corporate Data Through Office Brian Jones Program Manager Authoring Services Martin Sawicki Lead.
DEV334 Creating Application Starting Points & Sharing Best Practices with Enterprise Templates Marc Gusmano Director of Emerging Technologies The Information.
Programming with Visual Basic.NET An Object-Oriented Approach  Chapter 8 Introduction to Database Processing.
Introduction to ADO.Net and Visual Studio Database Tools ISYS 512.
OFC304 Excel 2003 Overview: XML Support Joseph Chirilov Program Manager.
CST238 Week 7 Questions / Concerns? Announcements – HW#2 due today (project concept/preliminary design) – Check-off Take Home lab#6 Friday is the last.
Developing Workflows with SharePoint Designer David Coe Application Development Consultant Microsoft Corporation.
Building Data Visualization Solutions with Visio 2007 Paul Holdaway Microsoft Consulting Services (UK)
Working with Numeric Variables (Unit 6) Visual Basic for Applications.
Numeric Variables Visual Basic for Applications 6.
DAT305 Boost Your Data-Driven Application Development Using SQL Server Centric.NET Code Generator Pascal Belaud Microsoft France.
OFC 303 Advanced Word XML: Customer-Defined Schemas Brian Jones Program Manager Authoring Services.
DEV325 Deploying Visual Studio.NET Applications Billy Hollis Author / Consultant.
DEV339 Best Practices for Debugging Visual Studio.NET Applications Keith Pleas Architect, Guided Design
OFC 308 Advanced Word XML: The WordML Schema and Bringing Everything Together Brian Jones Program Manager Authoring Services.
Data Binding in Depth DEV 419 Level 400 Eyal Vardi CEO Experts4D Microsoft VSTO MVP blog:
Delivering Excellence in Software Engineering ® EPAM Systems. All rights reserved. Data Binding in ASP.NET.
DEV337 Modeling Distributed Enterprise Applications Using UML in Visual Studio.NET David Keogh Program Manager Visual Studio Enterprise Tools.
Access Project 3 Notes. Introduction Maintaining the Database  Modifying the data to keep it up-to-date Restructure the Database  To change the database.
WaveMaker Visual AJAX Studio 4.0 Training Basics: Building Your First Application Binding Basics.
Module 4: Building DataSets. Overview Working in a Disconnected Environment Building DataSets and DataTables Binding and Saving a DataSet Defining Data.
Using Adapter Wizard ISYS 512. Data Adapter Wizard – 2 nd Level of Using ADO.Net Configure Data Adapter and generating a dataset: –From the Data tab of.
DEV333 Instrumenting Applications for Manageability with the Enterprise Instrumentation Framework David Keogh Program Manager Visual Studio Enterprise.
EBZ 321 Extending CMS 2002 Publishing Processes Scott Fynn Microsoft Consulting Services National Practices.
OFC291 Microsoft® Office Word XML (part 1 of 3): Introduction Martin Sawicki Lead Program Manager.
DEV303 ASP.NET: Leveraging Visual Studio.NET For Web Projects Tony Goodhew Product Manager Microsoft Corp.
DAT 332 SQL Server 2000 Data Transformation Services (DTS) Best Practices Euan Garden Product Unit Manager SQL Server Development Microsoft Corporation.
DEV330 Visual Studio.NET IDE Tips and Tricks Billy Hollis Author / consultant.
3 Copyright © 2004, Oracle. All rights reserved. Working in the Forms Developer Environment.
Introduction to ADO.Net and VS Database Tools and Data Binding ISYS 350.
Making the Most of WinForms 2.0 Data Binding Rajiv Sodhi Microsoft India.
DataBinding. Objectives List and explain the types of binding. Explain Binding Context and CurrencyManager class. List and explain the properties and.
MSG331 Exchange Server 2000/2003 Software Development Kit Susan Hill Lead Programmer Writer Microsoft Corporation.
DAT300 SQL Server Notification Services: Application Development Ken Henderson Technical Lead, SQL Server Support Microsoft Corporation
DEV393.NET Windows Forms Tips and Tricks Ken Getz Senior Consultant MCW Technologies, LLC.
Windows Forms in Visual Studio 2005: An in-depth look at key features Name: Joe Stegman Title: Lead Program Manager Session code.
WPF Data Binding Tomer Shamam Smart Client Team Leader Sela Group
EBIZ302 Jupiter Business Process Automation and Web Services David Fong Program Manager.
DEV394 Windows Forms Performance Tips And Tricks Mike Henderlight Development Manager.NET Client Team Microsoft Corporation
ASP.NET Data Binding. Slide 2 Lecture Overview Understanding the ASP.NET data binding model.
DEV332 Programming for the Middle Tier in Visual Basic.NET Billy Hollis Author / Consultant.
Effective C# 50 Specific Way to Improve Your C# Item 22, 23.
ADO.NET Objects Data Adapters Dr. Ron Eaglin. Agenda Builds on Information in Part I Should have working knowledge of creating a database connection Continuation.
Introduction to ADO.Net and Visual Studio Database Tools ISYS 350.
OFC320 Building EPM Solutions with Microsoft Project Server Ted Dinklocker Program Manager Microsoft Corp.
DAT 390 Advanced ADO.NET Programming Techniques Jackie Goldstein Renaissance Computer Systems
Using Data in Microsoft Visual Studio 2005 Tools for the Microsoft Office System Mike Hernandez Product Manager Visual Studio Tools for Office.
Creative Databinding With Delphi 8 for .NET
Visual C# 2005: IDE Enhancements
Avalon – Using Data In Your Applications
VB.NET Using Database.
Tech Ed North America /1/ :36 AM Required Slide
What's New in Visual Studio 2005
DEV312 基于WPF的数据绑定.
DEV322 Visual Studio 2005 C# IDE Enhancements
Windows Forms in Visual Studio 2005: An in-depth look at key features
Presentation transcript:

DEV397 Windows Forms Databinding Mike Henderlight Program Manager Windows Forms Microsoft Corporation

Agenda Introduction Basics Writing a data source

Databinding Goals Enable databinding to anything: Lists Indexed Collections (IList) DataSets Data Items Business objects *Any* object Make Control Development easier /more consistent

Assumptions “Three tier” is the driving scenario Disconnected data Finite numbers of records Datasources all share Indexable collections Consistent programming model Each List is homogeneous Examples DataSet Web Service returning an array of objects

Basics...

What is databinding? Automatic display & update of data Reduces the amount of “boilerplate” code you have to write Change notification Automatically updating data source from controls Automatically updating controls from datasource Managing the "current item"

Types of databinding “Simple databinding” Property to property Control has no knowledge of binding Standard across all controls Example: TextBox1.Text to Customer.Name “Complex databinding” Binding to the List Control has knowledge of binding Control dependent Example: DataGrid1.DataSource = Customers

Types of Datasource Array No change notification so: No Add/Delete Limited update Assumes "binding type" is array type IList (ArrayList, CollectionBase) No change notification so: No Add/Delete Limited update Assumes "binding type" is: indexed accessor type or first item in the list type Dim customers() As Customer public Customer this[int index] { get; } Default Public ReadOnly Property Item(index As Integer) As Customer

Types of Datasource IBindingList Change Notification so: Add Delete Update Sorting Searching Example: DataView

Binding Managers CurrencyManager Manages binding for a list Manages the "current" item Raises CurrentChanged and PositionChanged events Controls get “bindable list” from CurrencyManager Point of "consumer access" PropertyManager Similar to CurrencyManager but for single object

Binding Managers BindingContext Manages CurrencyManagers and PropertyManagers Typically for a Form For all contained controls Creates CurrencyManagers and PropertyManagers On demand based on a DataSource and a DataMember Controls get CurrencyManager from BindingContext Manages hierarchical relationships Based on DataMember Enables Master-Details

4 Set 2 Set BindingContext CurrencyManager Binding How it works... DataSource Customers[0].Name = “Bill” 1 TextChanged 2 Validated 3Set 2 Changed 1 Set 3 CurrentChanged1

What do you care about? Datasource: Property/ListChanged event Causes control value to update Control: PropertyChanged event Causes Binding to be marked as dirty Control: Validated event Causes new value to be pushed to data source Can stop this using CausesValidation property BindingContext: Get CurrencyManager for DataSource/DataMember CurrencyManager: Position: Changes current item Begin/End/CancelCurrent: Controls update of datasource List: Get the data source Current: Get the "current item" CurrentChanged/Position Changed events

Binding Basics Using the CurrencyManager demo demo

Tips and Tricks BindingContext: DataSource/DataMember is a key Different DS/DM means different CurrencyManager Validation: Driven by Leave event Does happen for Menus, Toolbar Can force using Form.Validate EndCurrentEdit: Required to flush datasource Me.BindingManager(dataSet1, “Customers”) DOES NOT EQUAL Me.BindingManager(dataSet1.Customers)

Master-Details (DataSet) Dataset: Bind thro’ the relationships: BindingContext creates a RelatedCurrencyManager DataGrid1.DataSource = DataSet1 DataGrid1.DataMember = “Customers” DataGrid2.DataSource = DataSet1 DataGrid2.DataMember = “Customers.CustOrders” DataGrid1.DataSource = DataSet1 DataGrid1.DataMember = _ “Customers.CustOrders.OrderOrderItems” “Customers.CustOrders.OrderOrderItems” Customers Orders OrderItems CustOrders OrderOrderItems

Master-Details (Objects) List: Bind thro’ the property names: BindingContext creates a RelatedCurrencyManager DataGrid1.DataSource = MyCustomersList DataGrid1.DataMember = “Customers” DataGrid2.DataSource = MyCustomersList DataGrid2.DataMember = “Customers.Orders” DataGrid1.DataSource = MyCustomersList DataGrid1.DataMember = “Customers.Orders.OrderItems” Customers Orders (OrdersCollection) OrderItems (OrderItemsCollection)

Master-Details demo demo

Lookup table You can use a ComboBox or ListBox as a “lookup” table Example: State field in Customer object Bind ComboBox to States collection Set DisplayValue to “value” property name Bind SelectedValue to Customer.State ComboBox1.DataSource = MyStates ComboBox1.DisplayMember = “LongName” ComboBox1.ValueMember = “ShortName” ComboBox1.DataBindings.Add _ (“SelectedValue”, DataSet1, “Customers.State”) (“SelectedValue”, DataSet1, “Customers.State”)

Lookup Table demo demo

Formatting Example: Format 12 as $12.00 Use the Format and Parse events on the Binding: Format and Parse are “paired” You need to do both Use BCL Formatting to actually format the value AddHandler TextBox1.DataBindings("Text").Format, _ AddressOf Me.TextBox1_Format AddressOf Me.TextBox1_FormattextBox1.DataBindings["Text"].Format +=new ConvertEventHandler(Form1_Format); +=new ConvertEventHandler(Form1_Format);

Formatting demo demo

Displaying errors You can set errors on the DataSet: Use ErrorProvider to display this information DataGrid automatically displays this information Use IDataErrorInfo on your business objects TIP: Don’t throw exceptions. We eat them! row.RowError = "You need to update the Widget price" row.SetColumnError("WidgetPrice", “Bad Widget Price")

Displaying Errors demo demo

Tips and Tricks (2) Datasets: You always bind to a DataView but not to the DefaultView The DataSet generates them on demand You can get to the DataView thro’ the CurrencyManager Use a DataViewManager to apply default Sorts and Filters Esp. useful for “child views” in a Master- Details Form

Using a DataViewManager demo demo

Writing a Data Source...

Datasource Interfaces Data Lists IList – indexed list IBindingList – list that supports change events searchable sortable IListSource – object that returns a list ITypedList – list with schema Data Items IEditableObject – Commit/Cancel IDataErrorInfo – error information ICustomTypeDescriptor – custom type information

IBindingList We will focus on change notification, Add, Remove, Update: public interface IBindingList : IList { // Properties bool AllowEdit { get; } bool AllowNew { get; } bool AllowRemove { get; }... bool SupportsChangeNotification { get; }... // Events public event ListChangedEventHandler ListChanged; // Methods... bool SupportsChangeNotification { get; }... // Events public event ListChangedEventHandler ListChanged; // Methods... object AddNew(); object AddNew();... }

Writing a custom data source demo demo

Community Resources Most Valuable Professional (MVP) Newsgroups Converse online with Microsoft Newsgroups, including Worldwide User Groups Meet and learn with your peers

evaluations evaluations

© 2003 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS SUMMARY.