313482 Info: Windows Form Data Binding Guide (from MSDN)

xiaoxiao2021-03-06  74

The release number of this article has been CHS313482

content

Summary

Overview Architecture Rapid Getting Started Example, Walks and Microsoft Knowledge Base Articles

Bind to DataView or DataViewManager Bind to an object or a set of objects to customize binding troubleshooting

Summary This article provides a guide to data binding in the Windows Form Application. Guide Articles Provide links to useful information, including online documents, Microsoft Knowledge Books, and Microsoft White Paper, the purpose is to help you understand Microsoft products or technology.

For additional information about the ADO.NET object, click the article number below to view the article in the Microsoft Knowledge Base:

313590 Info: RoadMap for ADO.NET (ADO.NET Guide)

Back to top

Overview The Windows Form Object Model provides a reliable data binding architecture that you can use the schema to write data providers and data users. The Windows Form Object Model supports the data provider based data binding and interface-based data binding. In addition, the Windows Form Object Model also supports multiple interfaces to extend existing control behavior and add a variety of binding behaviors to custom classes.

Windows forms can be bound to a class of public properties, or bind to support

Any class of the IList interface, for example

DataView class,

ARRAY class,

ArrayList class and

Collection class. Unlike the ASP.NET web form, the Windows Form Object Model does not support binding to

DataReader object or

The IEnumerable interface, because it needs to be backwarded backwards when binding any other objects of the non-simple object.

Back to top

Architecture Windows Form Object Model Supports two different binders:

PropertyManager CurrencyManager you can use

The PropertyManager class binds the simple control into a class of public properties. But can't use

PropertyManager Binds complex controls, for example

Listbox control,

ComboBOX control or

DataGrid control.

can use

CurrencyManager class binds simple controls or complex controls to support

Objects of the IList interface, for example

DataView object,

ARRAY object,

ArrayList object and

Collection object.

Use support

A custom class for the IBIndingList interface, you can sort the list, or add and delete items in the list. These controls are bound to the public properties of the object returned by the list. This object can support

The ICUSTOMTYPEDEScriptor interface is bound to an attribute of an index, not a public property. In addition, this object also supports

IepITableObject interface to provide you can pass

Beginedit method,

EndEdit method and

Canceledit method Access changes.

With bind to ADO

The Recordset object is different,

The ILIST interface does not track the "current" record. therefore,

ILIST interface does not include

MoveFirst method,

MoveNext method,

MovePRevious method and

MoveLast method.

CurrencyManager is through

Position attributes maintaining currency and you can increment and deliver this property to traverse records.

If you want to inform you when you navigate, make sure your application hook (HOOK)

Currencymanager

PositionChanged event. Also, if you want to notify you when any user changes (such as add, delete or sort), make sure your application hooks

IbindingList interface (DataView object implements this interface)

ListChanged event.

Typically, the data is not used to programmatically use the user interface. But use binding objects (usually

DataView) Change the data.

You can use the Microsoft Visual Studio .NET integration development environment (IDE) to bind controls to support when designing

Any class for the IComponent interface. You can also bind at runtime. Binding operations use two parameters: objects and properties.

The following code will

TextBox control and

DataGrid control Binds to the same

CurrencyManager and

DataView:

TextBox1.Databindings.add ("Text", DS, "Customers.customerid))

DataGrid1.datasource = DS

DataGrid1.datamember = "Customers" In addition, you can use the following code to bind to different

CurrencyManager and

DataView object:

TextBox1.Databindings.add ("Text", DS.Tables ("Customers"), "Customerid")

DataGrid1.datasource = DS.Tables ("Customers") The sample examples of the previous code show the same data. Editing and scrolling is not synchronized between the examples, but is synchronized in the example.

You can also traverse in the data binding syntax

DataRelation object. In the code below, the second

DataGrid Using Custord

Dataralation is displayed in the first one

ORDERS records for the current Customers record selected in DataGrid:

DataGrid1.datasource = DS

DataGrid1.DataMember = "Customers"

DataGrid2.DataSource = DS

DataGrid2.DataSource = "Customers.custord" To retrieve the foundation

CurrencyManager or

PropertyManager, please use the form

BindingContext properties. This will return forced to convert to

The appropriate manager of the BindingManagerBase base interface (you can convert the base class interface to the appropriate derived class):

Cm = ctype (Me.BindingContext (DS, "Customers"), CurrencyManager

CurrencyManager can pass

List attributes get a basic binding collection. If you know the derived type, you can force the returned object to the appropriate derived class:

DV = ctype (cm.list, dataview) 'okay if cm is bound to a dataview.

Al = ctype (cm.list, arraylist) 'okay if cm is bound to an arraylist. from

PropertyManager can pass

The Current property gains a basic binding object.

MyObject = ctype (PM.Current, MyClass) For more information on Windows Form Data Binding, see the topic of the following Microsoft Visual Studio .NET Help documents:

Visual Studio .Netvisual Basic and Visual C #

Create an application

Create a Windows application

Windows form

Windows Form Data Structure

Data Binding and Windows Forms Creating a Simple Binding Control on Windows Forms Windows Forms on Windows Forms User on Windows Forms User Navigation Data and Data Binding Interfaces in Windows Forms

Binding classes http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWindowsFormsBindingClassTopic.asp BindingContext class http://msdn.microsoft.com/library/default .asp? url = / library / en-us / cpref / html / fr1rfsystemWindowsformsbindingContextClasstopic.asp

Back to top

Quick Start Sample, Walkthrough and Microsoft Knowledge Base Article Quick Start Sample File provides an example of code for your reference. The drill provides some small tutorials to guide you through a typical application development solution. Microsoft Knowledge Base "How to" article provides a step-by-step guide related to how to complete specific tasks.

Visual Studio .NET help documentation provided in Sections, Quick Start Sample Files, Drivers and Microsoft Knowledge Base Article Description How to use Windows Forms Data Binding.

Quick Start Sample

Quick Start Sample Files are installed in one position in the following two locations. If you'll get a quick start sample file as part of the Visual Studio .Net, these sample files are located in the following folders:

C: / Program Files / Microsoft Visual Studio .NET / FRAMEWORKSDK / SAMPLES / QuickStart / ... If you use a quick start sample file as part of the Microsoft .NET Framework installed, these sample files are located in the following folder:

C: / Program files / frameworksdk / samples / quickstart / ...

drill

To access the drill, please in Visual Studio .NET

Click on the Help menu

index. in

Find text boxes, type

Walkthrough, Windows Form. The list of data access drills appears in the index result pane.

Microsoft Knowledge Base Article

Click here to view a list of "how to" articles related to Windows Form Data Binding

Back to top

The class that binds to DataView or DataViewManager is the most binding class.

DataView class. versus

Dataset,

DataTable or

Any binding of the DataViewManager object is derived from other classes.

The binding of the DataView class. If you have to put all controls with the same

DataView must be synchronized, you must or bind them all to the same

DataView object, or you must use a compatible binding syntax for

DataSource object is the same

DataView object.

Bind to

When the DataViewManager object, you can simultaneously

Multiple in dataset

DataTable object Settings Filters. When navigating in a hierarchy,

DataViewManager is generated with appropriate filters suitable for each layer in this hierarchy

DataView object.

drill

Http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbwlkwalkthroughdisplayingdatafromsingletableinwindowsform.asp simple data access in Windows Forms Walkthrough:: Walkthrough Windows display using parameterized queries data http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbwlkwalkthroughdisplayingdatainwindowsformusingparameterizedquery.asp form of exercise: Creating a master - slave relationship Windows Forms http: / /msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbwlkwalkthroughcreatingmaster-detailwindowsform.asp Using Windows Forms and .NET Bind http://msdn.microsoft. COM / library / default.asp? URL = / library / en-us / dndotnet / html / databindingadonet.asp Quick Getting Started

The data binding in the Windows Form http://www.gotdotnet.com/quickstart/winforms/doc/winformsdata.aspx If you install a quick start-up sample on your computer, the following subfolders also contain some additional examples:

... / Samples / QuickStart / WinForms / Samples / Data / ComboBoXBinding This subfolder Binds the Windows Forms ComboBox control to the array of custom classes, binding the TextBox control to the type DataSet, then use Vector button. ... / Samples / QuickStart / WinForms / Samples / Data / Grid This subfolder uses visual design tools to bind Windows Forms DataGrid controls to the type DataSet and populate the DataSet using the SqlDataAdapter object. ... / Samples / QuickStart / WinForms / Samples / Data / MasterDetails This subfolder includes a web service that discloses some ways to return and use the DataSet update master-from the relationship table. This example includes a client application that reads DataSet from the web service, then calls the web service to process parent changes and client changes. The client application is bound to a DataGrid type DataSet. Note: This example does not process all updates. In some updates, the error message may be displayed and the update may roll back. ... / Samples / QuickStart / WinForms / Samples / Data / SimpleBinding This subfolder Binds TextBox to the DataTable field and implements custom formats and analysis events. ... / Samples / QuickStart / WinForms / Samples / Data / Update This subfolder In this subfolder includes a web service that returns a DataTable through DataSet and handles the update to the client. This example includes a client application that uses the navigation buttons to bind DataTable to a TextBox and bind the ComboBox control to the array of custom objects. ... / Samples / QuickStart / WinForms / Samples / Data / WebServiceBinding This sample includes a web service that returns a DataTable via DataSet. This example does not include any update logic. The client application binds this DataTable to the Windows Forms DataGrid control. Visual Studio .NET Help Document

In the Windows Form Navigation http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbcondatanavigationinwindowsforms.asp

Microsoft Knowledge Base Article

317041 How to: Retrieve DataView of A Windows Forms Bound Control IN Visual Basic .NET (DataView for Windows Forms in Visual Basic .NET)

317164 How to: Retrieve DataView of a Windows Forms Bound Control In Visual C # .NET (DataView) of Windows Forms in Visual C # .NET)

308070 HOW TO: IMPLEMENT A Searchable DataGrid by Using ADO.NET and Windows Forms (use ADO.NET and Windows Forms to implement searchable data

317951 HOW TO: HIDE A Column in A Windows Form DataGrid hides a list in Windows Forms DataGrid 308484 How to: Display parent records and sub-records in DataGrid using the Windows Form using the Visual C # .NET

308052 HOW TO: Use the Windows Form in Visual Basic .NET to display parent records and subcords in DataGrid

308454 How to: Display Parent and child Fields Together In a DataGrid by Using Visual C # .NET (using Visual C # .NET to display parent fields and subfields together in DataGrid)

308057 How to: Display Parent and child Fields Together in A Windows Forms DataGrid by Using Visual Basic .NET (using Visual Basic .NET) Connected to the parent field and subfields while Windows Forms DataGrid)

307710 HOW TO: Custom Patement for Data Grid Windows Controls using Visual C # .NET

305271 HOW TO: Use Visual Basic .NET to custom paging for DataGrid Windows controls

Back to top

Bind to an object or a set of objects is bound to the simple class (ie, not supported

ILIST or

When the class of the ICUSTOMTYPEDEScriptor interface, the Bind Manager uses reflection to determine the public property of the class and allow the binding to these properties.

You can't

DataGrid or

ComboBox or

ListBox's list part binds to not support

IList interface object. If you will

DataGrid is bound to a list and if the object returned by the list does not support

ICUSTOMTYPEDESCRIPTOR

DataGrid binds a column to each public property of the class.

When you edit data in the binding control, the corresponding attribute of the binding object is updated immediately unless the object is implemented.

IEDITABLEOBJECT interface. If you change this property of the base object in programming, do not notify these changes to the binding control, unless the list object supports

IbindingList interface.

Quick Start Sample

The data binding in the Windows Form http://www.gotdotnet.com/quickstart/winforms/doc/winformsdata.aspx If you install a quick start-up sample on your computer, the following subfolders also contain some additional examples:

... / Samples / QuickStart / WinForms / Samples / Data / ComboBOBINDING This subfolder Binds Windows Forms ComboBox to an array of custom classes, binding a TextBox to the type of DataSet, then use Vector button. ... / Samples / QuickStart / WinForms / Samples / Data / SimpleBinding This subfolder Binds TextBox to the DataTable field and implements custom formats and analysis events. ... / Samples / QuickStart / WinForms / Samples / Data / Update This subfolder In this subfolder includes a web service that returns a DataTable through DataSet and handles the update to the client. This example includes a client application that binds the DATATABLE to a TextBox via a navigation button and binds a ComboBox list to an array of custom objects. Microsoft Knowledge Base Article

313334 How to: bind an array of structures to a windows form by using visual basic .net (using Visual Basic .NETT) Binds the structure to Windows Forms)

317551 How to: Format A Windows Forms DataGrid Bound To an Array In VC (Formatted Windows Forms DataGrid Binding to VC )

317550 How to: Use Visual C # .NET TO FORMAT A Windows Forms DataGrid That Is Bound to an Array (using Visual C # .NET Format Binding to a array of Windows Forms DataGrid)

317383 How to: Use Visual Basic .Net To Format A Windows Forms DataGrid That Is Bound To an Array (using Visual Basic .NET formatting Windows Forms DataGrid)

313636 How to: bind an arraylist of structures to a windows form by using visual c # .NET (using Visual C # .NET Binds ArrayList to Windows Form)

313640 How to: bind an arraylist or collection of objects to a windows form by using visual basic .net (using Visual Basic .NET to bind object's ArrayList or Collection to Windows Form)

313634 How to: bind an arraylist of objects to a windows form by using visual c # .NET (using Visual C # .NET Binds the object's ArrayList to Windows Form)

313335 How to: Bind An Array of Structures To A Windows Form By Using Visual C # .NET (using Visual C # .NET) Binds Array to Windows Forms 313639 How To: Bind An Array Of Objects To A Windows Form By Using Visual Basic .NET (using Visual Basic .NET to bind the object array to Windows Form)

313638 How to: bind an arraylist or collection of structures to a windows form by using visual basic .net (using Visual Basic .NET to bind the ArrayList or Collection to Windows Form)

313635 How to: bind an array of objects to a windows form by using visual c # .net (using Visual C # .NET to bind the object array to Windows Form)

316303 How to: bind a DataGrid Control to an ArrayList of Objects or Structures by Using Visual C # .NET (using Visual C # .net to bind DataGrid control ArrayList)

316302 how to: bind a datagrid control to an arraylist of objects or structures by using Visual Basic .NET (using Visual Basic .NET to bind DataGrid control ArrayList)

315786 How to: bind a DataGrid Control to an array of objects or structures by using Visual C # .NET (using Visual C # .net to bind DataGrid controls to an array of objects or structures)

315784 How to: bind a DataGrid Control to an array of objects or structures by using visual basic .net (using Visual Basic .NET to bind the DataGrid control to an array of objects or structures)

Back to top

Custom Bind You can hook the Windows Forms Frame to provide additional binding behaviors for custom classes and can change the binding behavior of the Windows Form Control.

Visual Studio .NET Help Document

Windows Form Data Architecture http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbCon/html/vboriwindowsformDataArchitecture.asp The interface http: // msdn is associated with data binding. Microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbconinterfacesrelatedtodatabase

Microsoft Knowledge Base Article

306227 HOW TO: Use a CheckBox Web Control in a DataGrid in Visual Studio .NET (using CheckBox Web control in a DataGrid in Visual Studio .NET) 318581 HOW TO: Extend the Windows Form DataGridTextBoxColumn Control to Custom-Format Data (the Windows window Body DataGridTextBoxColumn Control Extension to Custom Formats)

319082 How to: Extend The Windows Form DataGridTextBoxColumn To Display Data from Other Tables BY Using Visual Basic .NET (using Visual Basic .NET Extension Windows Forms DataGridTextBoxColumn to display data for other tables)

325682 HOW TO: IMPLEMENT A CUSTOM DATAVIEW CLASS IN VISUAL BASIC .NET (custom DataView class in Visual Basic .NET)

Back to top

Troubleshooting If you have questions or questions, please refer to the MSDN newsgroup, where you can share the experience of your peers. You can also use Microsoft Knowledge Base search for articles related to specific issues.

MSDN News Group http://msdn.microsoft.com/newsgroups/ Search Knowledge Base http://search.support.microsoft.com/kb/c.asp

Back to top

The information in this article applies to:

Microsoft ADO.NET (provided with .NET Framework) Microsoft .NET Framework SDK

Reserved: 2002-9-28 (1.0) Keyword kbarttyperoadmap kbdatabinding kbinfo kbnokeyword kbsystemData KB313482

转载请注明原文地址:https://www.9cbs.com/read-108988.html

New Post(0)