alt
Advertisement
Sponsored links
Online Training
Career Series
Exforsys
Exforsys arrow Tutorials arrow VB.NET 2005 arrow .NET Complex Data Binding
Site Search


.NET Complex Data Binding
Article Index
.NET Complex Data Binding
Page 2

In this tutorial you will learn about Complex Data Binding, Binding to a ComboBox or ListBox, Binding to a DataGrid.

Complex Data Binding

Complex data binding is the ability of a control to bind to more than one data element, typically more than one record in a database, or to more than one of any other type of bindable data elements. Examples of controls that support complex binding are the DataGridView, ListBox, and ErrorProvider controls.

Binding to a ComboBox or ListBox

In this section let us create a complex binding by using a ComboBox and a ListBox. As in the preceding section the user must add a database connection to the project and to generate DataSets. Then he must proceed to create a new Windows Application Project by name ComplexDataBindingDemo. After creating the Data Connection to the SQLServer Database, from the ToolBox, he must drag and drop a DataGrid control and a list box on the form Form1. At this point the user’s window should look like the following screenshot:

Here also the user will have to go through all the steps involved to set up the data providers and also bind them to the control. After doing this the user will have to set the value to the DataSource property of the controls to the data set. Now in some controls like ListBox and ComboBoxes the user will come across two properties viz, display member and value member. In a typical situation he will be needing the descriptive value of the column to be displayed while the use of the values like ProductId etc need to be passed as values to further queries. The user will have to set these values also.

The following screenshots will show the output for ComplexBinding using a combo box, list box and a DataGrid.

Binding to a DataGrid

A DataGrid is a very useful Control. A number of improvements have been made to this control in .NET Framework 2005. Binding Data to DataGrid is simple. As a first step, The user has to set the value for the property Advanced Binding and DataSource.

1. Create a new project in Visual Studio and add a label, a button and a grid control.

2. Set the value for text property of the Label and that of the button as Exit.

3. Write code to close the form.

4. Drag and drop one DataGrid on the form from the ToolBox.

5. Set the value of the propery Datasource as the DataSet.DataTable. The user can do the property editing also using SmartTags.

The following screenshot shows the final appearance of the DataGrid

Figure 4-11 The Data Component Configuration Wizard.



 
< Prev   Next >
Exforsys Offers
© 2008 Exforsys.com
Joomla! is Free Software released under the GNU/GPL License.
Page copy protected against web site content infringement by Copyscape