VB.NET Master Detail DataGridView Control

  • Thread starter Adnan Abbasi via DotNetMonster.com
  • Start date
A

Adnan Abbasi via DotNetMonster.com

Hi,
I m a newbie to VB.NET. So, i have problem in doing some tasks like
Master/Detail working with DATAGRID VIEW object along with BindNavigator.

How can i implement Master / Detail that work with the BindingNavigator?

Your advice will be highly appreciated.

Adnan A.
 
R

RobinS

This has been asked an answered a bunch of times. Google is your friend.
Here's my post from within the last month or so.

This example is for a form with two grids on it. One grid is the parent,
the other is the children, and the textboxes are bound to the parent.

I have a dataset that has two tables: Customers and Orders. (This runs
against Northwind, so if you have that installed, you can try this out.)

I set up a strongly-typed dataset using the Data Set Designer with both of
those tables in it, and there is a field called CustomerID in the Orders
table that links to the CustomerID table in Customers. So Orders have a
Customer as a parent. The data relation between the customer and the orders
is defined as FK_Orders_Customers.

(You can set up your dataset however you like.)

This is in Form_Load:

'First, populate the dataset.
Dim nwData As CustomersDataSet = CustomersDataSet.GetCustomers()

'Set the data source for the binding source to the dataset.
CustomersBindingSource.DataSource = nwData
'Add this so it knows which table to use .
CustomersBindingSource.DataMember = "Customers"
'Set the data source for the grid to the customers binding source.
CustomersDataGridView.DataSource = CustomersBindingSource

'Add the binding for the child; set its binding source to the same
' one as the parent.
Customers_OrdersBindingSource.DataSource = CustomersBindingSource
'Set the datamember to the foreign key joining the two tables.
' You can see this on your CustomersDataSet diagram.
Customers_OrdersBindingSource.DataMember = "FK_Orders_Customers"
'Set the data source on the child grid to points at its
' binding source.
OrdersDataGridView.DataSource = Customers_OrdersBindingSource

This information came out of Brian Noyes's book on Data Binding.

Bind the BindingNavigator to the parent data source, in this example the
CustomersBindingSource.

Robin S.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top