Binding Data to Controls
Simple data binding is the ability to bind a control to a single data element. When you need to display and manipulate more than one data element at a time,then this is called complex data binding.Complex data binding is the ability to bind a control to more than one data element and more than one record in a database.
Class Hierarchies Relevant to Data Binding
|
Methods Binding
For ListBox controls, you can bind the control to aDataSet class using the DataSource and DisplayMemberproperties as you have seen in our Windows Forms example:
ListBox1.DataSource = customer
ListBox1.DisplayMember = "Customers.CompanyName"
Or, you can use the DataBinding method programmatically to achieve the same results.
ListBox1.DataBindings.Add(New System.Windows.Forms.Binding
("SelectedItem", customer, "Customers.CompanyName"))
For DataGrid controls, you bind the control to a DataSetclass using the DataSource and DataMember properties:
DataGrid1.DataMember = "Customers.CustomersOrders"
DataGrid1.DataSource = customer
Or, use the SetDataBinding method programmatically to achieve the same results:
DataGrid1.SetDataBinding(customer,"Customers.CustomersOrders")
0 comments:
Post a Comment