473,386 Members | 1,773 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

data binding to show 3 layer M/S tables in datagrid

Hi,

I have 3 talbes "customers","orders","details". i wanna to use 3 datagrids
to show those tables. and when the selected row in parent talbe changes, the
selected row in child table changes automaticly. If there is only 2 tables,
that's quite easy. add the relation "CusVsOrder" to dataset. binding the
"patient" with the parent datagrid, binding the relation
"customers.CusVsOrder" with the child datagrid. while, now there are 3
tables, and two one-to-many relations in the dataset. anyone know how to
realize it?
I figure out an unefficient method, the codes are showed as following, while
a question raised,what's is the event for the datagrid when the selected row
changed?

Thanks in advance.
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
OleDbDataAdapter1.Fill(DataSet11)
OleDbDataAdapter2.Fill(DataSet11)
OleDbDataAdapter3.Fill(DataSet11)
'add relations "customers.CusVsOrder" and "orders.OrdVsDet" here.
code ignored
...
DataGrid1.DataMember = "customers"
DataGrid2.DataMember = "customers.CusVsOrder"
DataGrid3.DataMember = "orders"
DataGrid4.DataMember = "orders.OrdVsDet"
bind1 = BindingContext(DataSet11, "customers")
bind2 = BindingContext(DataSet11, customers
bind3 = BindingContext(DataSet11, "orders")
bind4 = BindingContext(DataSet11, "orders.OrdVsDet")
If bind2.Position < 0 Then
bind3.Position = bind2.Position
Else
Dim a, b As DataRowView
Dim id As Integer
a = CType(bind2.Current, DataRowView)
id = a.Row("orderID")
Dim c As DataRow
Dim i As Integer
For i = 0 To DataSet11.Tables("orders").Rows.Count - 1
bind3.Position = i
b = CType(bind3.Current, DataRowView)
If id = b.Row("orderID") Then
Exit For
End If
Next
End If

AddHandler bind2.PositionChanged, _
AddressOf bind2_PositionChanged

' addhander to handle the event when the select row in datagrid2 changed?
....

end sub
Private Sub bind2_PositionChanged _
(ByVal sender As Object, ByVal e As EventArgs)

If bind2.Position < 0 Then
bind3.Position = bind2.Position
Else
If Not bind2.Current Is Nothing Then
Dim a, b As DataRowView
Dim id As Integer
a = CType(bind2.Current, DataRowView)
id = a.Row("orderID")
Dim c As DataRow
Dim i As Integer
For i = 0 To DataSet11.Tables("orders").Rows.Count - 1
bind3.Position = i
b = CType(bind3.Current, DataRowView)
If id = b.Row("orderID") Then
Exit For
End If
Next
End If
End If
End Sub
Nov 21 '05 #1
2 1741
yuanh23,
The following sample using 3 grids uses the Northwind Sample SQL Server
database:

customerAdapter.Fill(customerDataSet, "Customers")
orderAdapter.Fill(customerDataSet, "Orders")
orderDetailsAdapter.Fill(customerDataSet, "OrderDetails")

' Create relationships.
customerDataSet.Relations.Add("CustomerOrders", _
customerDataSet.Tables("Customers").Columns("Custo merID"), _
customerDataSet.Tables("Orders").Columns("Customer ID"))

customerDataSet.Relations.Add("OrderDetails", _
customerDataSet.Tables("Orders").Columns("OrderID" ), _
customerDataSet.Tables("OrderDetails").Columns("Or derID"))

' Bind to the DataGrids.
Me.DataGrid1.SetDataBinding(customerDataSet, _
"Customers")
Me.DataGrid2.SetDataBinding(customerDataSet, _
"Customers.CustomerOrders")
Me.DataGrid3.SetDataBinding(customerDataSet, _
"Customers.CustomerOrders.OrderDetails")

Notice that the first grid is bound to Customers. The second grid is bound
to Orders that are related to Customers, the "Customers.CustomerOrders".
While the third grid is bound to OrderDetails that are related to Orders
that are related to Customers, the "Customers.CustomerOrders.OrderDetails".

When the selection changes in the first grid, the contents of the second two
grids will change. When the selection of the second grid changes, the
contents of the third grid changes.

Hope this helps
Jay
"yuanh23" <yu*****@hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi,

I have 3 talbes "customers","orders","details". i wanna to use 3 datagrids
to show those tables. and when the selected row in parent talbe changes,
the
selected row in child table changes automaticly. If there is only 2
tables,
that's quite easy. add the relation "CusVsOrder" to dataset. binding the
"patient" with the parent datagrid, binding the relation
"customers.CusVsOrder" with the child datagrid. while, now there are 3
tables, and two one-to-many relations in the dataset. anyone know how to
realize it?
I figure out an unefficient method, the codes are showed as following,
while
a question raised,what's is the event for the datagrid when the selected
row
changed?

Thanks in advance.
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
OleDbDataAdapter1.Fill(DataSet11)
OleDbDataAdapter2.Fill(DataSet11)
OleDbDataAdapter3.Fill(DataSet11)
'add relations "customers.CusVsOrder" and "orders.OrdVsDet" here.
code ignored
...
DataGrid1.DataMember = "customers"
DataGrid2.DataMember = "customers.CusVsOrder"
DataGrid3.DataMember = "orders"
DataGrid4.DataMember = "orders.OrdVsDet"
bind1 = BindingContext(DataSet11, "customers")
bind2 = BindingContext(DataSet11, customers
bind3 = BindingContext(DataSet11, "orders")
bind4 = BindingContext(DataSet11, "orders.OrdVsDet")
If bind2.Position < 0 Then
bind3.Position = bind2.Position
Else
Dim a, b As DataRowView
Dim id As Integer
a = CType(bind2.Current, DataRowView)
id = a.Row("orderID")
Dim c As DataRow
Dim i As Integer
For i = 0 To DataSet11.Tables("orders").Rows.Count - 1
bind3.Position = i
b = CType(bind3.Current, DataRowView)
If id = b.Row("orderID") Then
Exit For
End If
Next
End If

AddHandler bind2.PositionChanged, _
AddressOf bind2_PositionChanged

' addhander to handle the event when the select row in datagrid2 changed?
...

end sub
Private Sub bind2_PositionChanged _
(ByVal sender As Object, ByVal e As EventArgs)

If bind2.Position < 0 Then
bind3.Position = bind2.Position
Else
If Not bind2.Current Is Nothing Then
Dim a, b As DataRowView
Dim id As Integer
a = CType(bind2.Current, DataRowView)
id = a.Row("orderID")
Dim c As DataRow
Dim i As Integer
For i = 0 To DataSet11.Tables("orders").Rows.Count - 1
bind3.Position = i
b = CType(bind3.Current, DataRowView)
If id = b.Row("orderID") Then
Exit For
End If
Next
End If
End If
End Sub

Nov 21 '05 #2
Hi, Jay,
It really help me a lot. Thank you:)

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:OU**************@TK2MSFTNGP10.phx.gbl...
yuanh23,
The following sample using 3 grids uses the Northwind Sample SQL Server
database:

customerAdapter.Fill(customerDataSet, "Customers")
orderAdapter.Fill(customerDataSet, "Orders")
orderDetailsAdapter.Fill(customerDataSet, "OrderDetails")

' Create relationships.
customerDataSet.Relations.Add("CustomerOrders", _
customerDataSet.Tables("Customers").Columns("Custo merID"), _
customerDataSet.Tables("Orders").Columns("Customer ID"))

customerDataSet.Relations.Add("OrderDetails", _
customerDataSet.Tables("Orders").Columns("OrderID" ), _
customerDataSet.Tables("OrderDetails").Columns("Or derID"))

' Bind to the DataGrids.
Me.DataGrid1.SetDataBinding(customerDataSet, _
"Customers")
Me.DataGrid2.SetDataBinding(customerDataSet, _
"Customers.CustomerOrders")
Me.DataGrid3.SetDataBinding(customerDataSet, _
"Customers.CustomerOrders.OrderDetails")

Notice that the first grid is bound to Customers. The second grid is bound
to Orders that are related to Customers, the "Customers.CustomerOrders".
While the third grid is bound to OrderDetails that are related to Orders
that are related to Customers, the "Customers.CustomerOrders.OrderDetails".
When the selection changes in the first grid, the contents of the second two grids will change. When the selection of the second grid changes, the
contents of the third grid changes.

Hope this helps
Jay
"yuanh23" <yu*****@hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi,

I have 3 talbes "customers","orders","details". i wanna to use 3 datagrids to show those tables. and when the selected row in parent talbe changes,
the
selected row in child table changes automaticly. If there is only 2
tables,
that's quite easy. add the relation "CusVsOrder" to dataset. binding the
"patient" with the parent datagrid, binding the relation
"customers.CusVsOrder" with the child datagrid. while, now there are 3
tables, and two one-to-many relations in the dataset. anyone know how to
realize it?
I figure out an unefficient method, the codes are showed as following,
while
a question raised,what's is the event for the datagrid when the selected
row
changed?

Thanks in advance.
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
OleDbDataAdapter1.Fill(DataSet11)
OleDbDataAdapter2.Fill(DataSet11)
OleDbDataAdapter3.Fill(DataSet11)
'add relations "customers.CusVsOrder" and "orders.OrdVsDet" here.
code ignored
...
DataGrid1.DataMember = "customers"
DataGrid2.DataMember = "customers.CusVsOrder"
DataGrid3.DataMember = "orders"
DataGrid4.DataMember = "orders.OrdVsDet"
bind1 = BindingContext(DataSet11, "customers")
bind2 = BindingContext(DataSet11, customers
bind3 = BindingContext(DataSet11, "orders")
bind4 = BindingContext(DataSet11, "orders.OrdVsDet")
If bind2.Position < 0 Then
bind3.Position = bind2.Position
Else
Dim a, b As DataRowView
Dim id As Integer
a = CType(bind2.Current, DataRowView)
id = a.Row("orderID")
Dim c As DataRow
Dim i As Integer
For i = 0 To DataSet11.Tables("orders").Rows.Count - 1
bind3.Position = i
b = CType(bind3.Current, DataRowView)
If id = b.Row("orderID") Then
Exit For
End If
Next
End If

AddHandler bind2.PositionChanged, _
AddressOf bind2_PositionChanged

' addhander to handle the event when the select row in datagrid2 changed? ...

end sub
Private Sub bind2_PositionChanged _
(ByVal sender As Object, ByVal e As EventArgs)

If bind2.Position < 0 Then
bind3.Position = bind2.Position
Else
If Not bind2.Current Is Nothing Then
Dim a, b As DataRowView
Dim id As Integer
a = CType(bind2.Current, DataRowView)
id = a.Row("orderID")
Dim c As DataRow
Dim i As Integer
For i = 0 To DataSet11.Tables("orders").Rows.Count - 1
bind3.Position = i
b = CType(bind3.Current, DataRowView)
If id = b.Row("orderID") Then
Exit For
End If
Next
End If
End If
End Sub


Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Frazer | last post by:
hi i have a combo box which i populate with all tables from northwind database and when the user selects an item from the combo, i want to populate the datagrid with data from that table. ...
5
by: pmud | last post by:
Hi, I need to display columns in a data grid based on 7 different queries. Now I have 32 questions: 1. Is it possble to have 1 single data adapter with 7 queries & 1 data set or do I need to...
1
by: sandman | last post by:
I've got a simple windows form with some bound textboxes and Save button. Each texbox is bound to column in a table in an Access database. The form fills fine - all the fields show the correct...
2
by: Josef Meile | last post by:
Hi, I'm using a ComboBox, some Textboxes, and a DataGrid to represent a many-to-many relationship between Person and Course. Each time that I change the value in the ComboBox (which for now is...
6
by: Tejpal Garhwal | last post by:
I have datagrid filled with some data rows. At the run time i want know how many total rows are there in the data grid ? Any idea ? Any Suggestions ? Thanks in advance Tej
10
by: Doug Bell | last post by:
Hi, I have an application that has a "Data Access Class" and "User Interface Class". It is for receiving Purchase Order data from one system and pushing processed transactions to another...
3
by: no | last post by:
Hi all, I have a dataset that contain 2 tables and a relationship between them (master detail). I bind this dataset to a form that include some textboxes that bind to the parent record, and a...
9
by: Anil Gupte | last post by:
After reading a tutorial and fiddling, I finally got this to work. I can now put two tables created with a DataTable class into a DataRelation. Phew! And it works! Dim tblSliceInfo As New...
12
by: Randy | last post by:
Hi, Trying to pass along a table row delete to the datasource, but I'm crashing. Here is the code: Private Sub btnDeleteIngr_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.