Master-> Detail-> Detail with datagrids

  • Thread starter Thread starter solex
  • Start date Start date
S

solex

Hello,

I am trying (unsuccessfully) to display a Master-Detail-Detail records. The
problem comes in the second detail grid. The first detail grid is
displaying correctly but it is not controlling the second grid. Here is
some code that I am using to initialize the binding:

txtName.DataBindings.Add("Text", dsFundOwner, "FundOwner.Name")
txtNote.DataBindings.Add("Text", dsFundOwner, "FundOwner.Note")
txtInformationSource.DataBindings.Add("Text", dsFundOwner,
"FundOwner.InformationSource")
txtLocation.DataBindings.Add("Text", dsFundOwner, "FundOwner.LocationState")
txtCountry.DataBindings.Add("Text", dsFundOwner, "FundOwner.Country")
txtFounder.DataBindings.Add("Text", dsFundOwner, "FundOwner.Founder")
txtTotalManaged.DataBindings.Add("Text", dsFundOwner,
"FundOwner.TotalManaged")
txtTotalManagedNotes.DataBindings.Add("Text", dsFundOwner,
"FundOwner.TotalManagedNotes")
txtRaiseNewFund.DataBindings.Add("Text", dsFundOwner,
"FundOwner.ExpectedToRaiseNewFund")
txtNewFundDate.DataBindings.Add("Text", dsFundOwner,
"FundOwner.ExpectedToRaiseNewFundDate")
dgSubsidiaries.DataSource = dsFundOwner
dgSubsidiaries.DataMember = "FundOwner.FundOwner_Subsidiary"

' This grid is not displaying correctly when the dgSubsidiaries record
pointer is changed
dgFunds.DataSource = dsFundOwner
dgFunds.DataMember = "Subsidiary.Subsidiary_Fund"

Any Suggestions?

Thanks,
Dan
 
Hi,

Use Datagrid.SetDatabinding. Here is an example which uses the
northwind database.

Dim ds As DataSet

Dim daEmployees As SqlDataAdapter

Dim daOrders As SqlDataAdapter

Dim daOrderDetails As SqlDataAdapter

Dim conn As SqlConnection

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 = "Server = " + Environment.MachineName + "\VSdotNet;"

strConn += "Database = NorthWind;"

strConn += "Integrated Security = SSPI;"

conn = New SqlConnection(strConn)

ds = New DataSet

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

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

daOrderDetails = New SqlDataAdapter("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.SetDataBinding(ds, "Employee")

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

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



Ken

-------------------
 
Back
Top