master/details

G

Guest

Hey all,

I'm using Northwind Customers and Orders tables. And I'm trying to build a
3-tier logical architecture app. My problem is I have a form that lists all
the customers in a datagrid. I want to be able to click on a customer and
show form 2 with the details of that customer and another datagrid of the
orders below.

I'm trying to pass just one business object that has the dataset wrapped in
it. When I pass the business object to the second form I can't get the
datagrid to sync with the selected customer. It keeps defaulting I guess to
the first customer of the customers' table. How can I sync my orders datagrid
with the selected customer?

Thanks in advance,
rodchar
 
K

Ken Tucker [MVP]

Hi,

Here is an example that uses datareleations to keep 3 grids in sync.
Place 3 datagrid grids on the form dgorders, dgorderdetails, dgemployees.


Dim ds As DataSet

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim daEmployees As OleDbDataAdapter

Dim daOrders As OleDbDataAdapter

Dim daOrderDetails As OleDbDataAdapter

Dim conn As OleDbConnection

Dim strConn As String

Dim strSQL As String

Dim strItem As String

Dim ctrl As Control

For Each ctrl In Me.Controls

If TypeOf ctrl Is DataGrid Then

Dim dg As DataGrid = ctrl

dg.AllowNavigation = False

End If

Next

strConn = "Provider = Microsoft.Jet.OLEDB.4.0;"

strConn &= "Data Source = Northwind.mdb;"



conn = New OleDbConnection(strConn)

ds = New DataSet

daEmployees = New OleDbDataAdapter("Select * from Employees", conn)

daOrders = New OleDbDataAdapter("Select * from Orders", conn)

daOrderDetails = New OleDbDataAdapter("Select * from [Order Details]", conn)

daEmployees.Fill(ds, "Employee")

daOrders.Fill(ds, "Orders")

daOrderDetails.Fill(ds, "OrderDetails")

ds.Relations.Add("EmployeeOrder",
ds.Tables("Employee").Columns("EmployeeID"), _

ds.Tables("Orders").Columns("EmployeeID"))

ds.Relations.Add("Order2Details", ds.Tables("Orders").Columns("OrderID"), _

ds.Tables("OrderDetails").Columns("OrderID"))

dgEmployees.ReadOnly = True

dgOrders.ReadOnly = True

dgOrderDetails.ReadOnly = True

dgEmployees.SetDataBinding(ds, "Employee")

dgOrders.SetDataBinding(ds, "Employee.EmployeeOrder")

dgOrderDetails.SetDataBinding(ds, "Employee.EmployeeOrder.Order2Details")

End Sub



Ken

----------------------------


Hey all,

I'm using Northwind Customers and Orders tables. And I'm trying to build a
3-tier logical architecture app. My problem is I have a form that lists all
the customers in a datagrid. I want to be able to click on a customer and
show form 2 with the details of that customer and another datagrid of the
orders below.

I'm trying to pass just one business object that has the dataset wrapped in
it. When I pass the business object to the second form I can't get the
datagrid to sync with the selected customer. It keeps defaulting I guess to
the first customer of the customers' table. How can I sync my orders
datagrid
with the selected customer?

Thanks in advance,
rodchar
 
G

Guest

Well I have a working example of 2 datagrids on one form but if I pick a
customer from a datagrid on form1 and open up form2 to show the orders for
that customer in another datagrid I get lost in the concept.
 
K

Ken Tucker [MVP]

Hi,

http://msdn.microsoft.com/library/d...rfSystemDataDataRowClassGetChildRowsTopic.asp

Ken
---------------------
Well I have a working example of 2 datagrids on one form but if I pick a
customer from a datagrid on form1 and open up form2 to show the orders for
that customer in another datagrid I get lost in the concept.

Ken Tucker said:
Hi,

Here is an example that uses datareleations to keep 3 grids in
sync.
Place 3 datagrid grids on the form dgorders, dgorderdetails, dgemployees.


Dim ds As DataSet

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim daEmployees As OleDbDataAdapter

Dim daOrders As OleDbDataAdapter

Dim daOrderDetails As OleDbDataAdapter

Dim conn As OleDbConnection

Dim strConn As String

Dim strSQL As String

Dim strItem As String

Dim ctrl As Control

For Each ctrl In Me.Controls

If TypeOf ctrl Is DataGrid Then

Dim dg As DataGrid = ctrl

dg.AllowNavigation = False

End If

Next

strConn = "Provider = Microsoft.Jet.OLEDB.4.0;"

strConn &= "Data Source = Northwind.mdb;"



conn = New OleDbConnection(strConn)

ds = New DataSet

daEmployees = New OleDbDataAdapter("Select * from Employees", conn)

daOrders = New OleDbDataAdapter("Select * from Orders", conn)

daOrderDetails = New OleDbDataAdapter("Select * from [Order Details]",
conn)

daEmployees.Fill(ds, "Employee")

daOrders.Fill(ds, "Orders")

daOrderDetails.Fill(ds, "OrderDetails")

ds.Relations.Add("EmployeeOrder",
ds.Tables("Employee").Columns("EmployeeID"), _

ds.Tables("Orders").Columns("EmployeeID"))

ds.Relations.Add("Order2Details", ds.Tables("Orders").Columns("OrderID"),
_

ds.Tables("OrderDetails").Columns("OrderID"))

dgEmployees.ReadOnly = True

dgOrders.ReadOnly = True

dgOrderDetails.ReadOnly = True

dgEmployees.SetDataBinding(ds, "Employee")

dgOrders.SetDataBinding(ds, "Employee.EmployeeOrder")

dgOrderDetails.SetDataBinding(ds, "Employee.EmployeeOrder.Order2Details")

End Sub



Ken

----------------------------


Hey all,

I'm using Northwind Customers and Orders tables. And I'm trying to build a
3-tier logical architecture app. My problem is I have a form that lists
all
the customers in a datagrid. I want to be able to click on a customer and
show form 2 with the details of that customer and another datagrid of the
orders below.

I'm trying to pass just one business object that has the dataset wrapped
in
it. When I pass the business object to the second form I can't get the
datagrid to sync with the selected customer. It keeps defaulting I guess
to
the first customer of the customers' table. How can I sync my orders
datagrid
with the selected customer?

Thanks in advance,
rodchar
 
G

Guest

I've seen this example before. I remember a slight problem I had which was
when I got the child rows in the data row array I tried to bind that to a
datagrid. It kinda worked in that I got extra fields such as "Has Error",
"Row state", etc. and I tried to use the Table Styles but that didn't seem to
affect it.

Now, Cor gave some advice to me about this and I'm currently reviewing it. I
think the advice he gave is kinda over my head but I'm trying. I'll let you
know.

thanks,
rodchar

Ken Tucker said:
Hi,

http://msdn.microsoft.com/library/d...rfSystemDataDataRowClassGetChildRowsTopic.asp

Ken
---------------------
Well I have a working example of 2 datagrids on one form but if I pick a
customer from a datagrid on form1 and open up form2 to show the orders for
that customer in another datagrid I get lost in the concept.

Ken Tucker said:
Hi,

Here is an example that uses datareleations to keep 3 grids in
sync.
Place 3 datagrid grids on the form dgorders, dgorderdetails, dgemployees.


Dim ds As DataSet

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim daEmployees As OleDbDataAdapter

Dim daOrders As OleDbDataAdapter

Dim daOrderDetails As OleDbDataAdapter

Dim conn As OleDbConnection

Dim strConn As String

Dim strSQL As String

Dim strItem As String

Dim ctrl As Control

For Each ctrl In Me.Controls

If TypeOf ctrl Is DataGrid Then

Dim dg As DataGrid = ctrl

dg.AllowNavigation = False

End If

Next

strConn = "Provider = Microsoft.Jet.OLEDB.4.0;"

strConn &= "Data Source = Northwind.mdb;"



conn = New OleDbConnection(strConn)

ds = New DataSet

daEmployees = New OleDbDataAdapter("Select * from Employees", conn)

daOrders = New OleDbDataAdapter("Select * from Orders", conn)

daOrderDetails = New OleDbDataAdapter("Select * from [Order Details]",
conn)

daEmployees.Fill(ds, "Employee")

daOrders.Fill(ds, "Orders")

daOrderDetails.Fill(ds, "OrderDetails")

ds.Relations.Add("EmployeeOrder",
ds.Tables("Employee").Columns("EmployeeID"), _

ds.Tables("Orders").Columns("EmployeeID"))

ds.Relations.Add("Order2Details", ds.Tables("Orders").Columns("OrderID"),
_

ds.Tables("OrderDetails").Columns("OrderID"))

dgEmployees.ReadOnly = True

dgOrders.ReadOnly = True

dgOrderDetails.ReadOnly = True

dgEmployees.SetDataBinding(ds, "Employee")

dgOrders.SetDataBinding(ds, "Employee.EmployeeOrder")

dgOrderDetails.SetDataBinding(ds, "Employee.EmployeeOrder.Order2Details")

End Sub



Ken

----------------------------


Hey all,

I'm using Northwind Customers and Orders tables. And I'm trying to build a
3-tier logical architecture app. My problem is I have a form that lists
all
the customers in a datagrid. I want to be able to click on a customer and
show form 2 with the details of that customer and another datagrid of the
orders below.

I'm trying to pass just one business object that has the dataset wrapped
in
it. When I pass the business object to the second form I can't get the
datagrid to sync with the selected customer. It keeps defaulting I guess
to
the first customer of the customers' table. How can I sync my orders
datagrid
with the selected customer?

Thanks in advance,
rodchar
 
K

Ken Tucker [MVP]

Hi,

http://www.onteorasoftware.com/downloads/2formrelation.zip

Ken
---------------
I've seen this example before. I remember a slight problem I had which was
when I got the child rows in the data row array I tried to bind that to a
datagrid. It kinda worked in that I got extra fields such as "Has Error",
"Row state", etc. and I tried to use the Table Styles but that didn't seem
to
affect it.

Now, Cor gave some advice to me about this and I'm currently reviewing it. I
think the advice he gave is kinda over my head but I'm trying. I'll let you
know.

thanks,
rodchar

Ken Tucker said:
Hi,

http://msdn.microsoft.com/library/d...rfSystemDataDataRowClassGetChildRowsTopic.asp

Ken
---------------------
Well I have a working example of 2 datagrids on one form but if I pick a
customer from a datagrid on form1 and open up form2 to show the orders for
that customer in another datagrid I get lost in the concept.

Ken Tucker said:
Hi,

Here is an example that uses datareleations to keep 3 grids in
sync.
Place 3 datagrid grids on the form dgorders, dgorderdetails,
dgemployees.


Dim ds As DataSet

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Dim daEmployees As OleDbDataAdapter

Dim daOrders As OleDbDataAdapter

Dim daOrderDetails As OleDbDataAdapter

Dim conn As OleDbConnection

Dim strConn As String

Dim strSQL As String

Dim strItem As String

Dim ctrl As Control

For Each ctrl In Me.Controls

If TypeOf ctrl Is DataGrid Then

Dim dg As DataGrid = ctrl

dg.AllowNavigation = False

End If

Next

strConn = "Provider = Microsoft.Jet.OLEDB.4.0;"

strConn &= "Data Source = Northwind.mdb;"



conn = New OleDbConnection(strConn)

ds = New DataSet

daEmployees = New OleDbDataAdapter("Select * from Employees", conn)

daOrders = New OleDbDataAdapter("Select * from Orders", conn)

daOrderDetails = New OleDbDataAdapter("Select * from [Order Details]",
conn)

daEmployees.Fill(ds, "Employee")

daOrders.Fill(ds, "Orders")

daOrderDetails.Fill(ds, "OrderDetails")

ds.Relations.Add("EmployeeOrder",
ds.Tables("Employee").Columns("EmployeeID"), _

ds.Tables("Orders").Columns("EmployeeID"))

ds.Relations.Add("Order2Details",
ds.Tables("Orders").Columns("OrderID"),
_

ds.Tables("OrderDetails").Columns("OrderID"))

dgEmployees.ReadOnly = True

dgOrders.ReadOnly = True

dgOrderDetails.ReadOnly = True

dgEmployees.SetDataBinding(ds, "Employee")

dgOrders.SetDataBinding(ds, "Employee.EmployeeOrder")

dgOrderDetails.SetDataBinding(ds,
"Employee.EmployeeOrder.Order2Details")

End Sub



Ken

----------------------------


Hey all,

I'm using Northwind Customers and Orders tables. And I'm trying to build
a
3-tier logical architecture app. My problem is I have a form that lists
all
the customers in a datagrid. I want to be able to click on a customer
and
show form 2 with the details of that customer and another datagrid of
the
orders below.

I'm trying to pass just one business object that has the dataset wrapped
in
it. When I pass the business object to the second form I can't get the
datagrid to sync with the selected customer. It keeps defaulting I guess
to
the first customer of the customers' table. How can I sync my orders
datagrid
with the selected customer?

Thanks in advance,
rodchar
 

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