Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parent - Child data ....

Status
Not open for further replies.

Vandy02

Programmer
Jan 7, 2003
151
US
I have to routines...
btnData_Click - I get data from a database)DEPT / EMP tables... and load data into a dataset(ds) as two tables DEPT/EMP....EMP is a child table...many emps to one DEPT....I add the data to datagrids dgDEPT and dgEMP so can see that the data exists....

If I click on btnData_Click I want to be able to show the children of dgDEPT of the based on the CURRENTROWINDEX of which I have setup for output in dgDEPT_CurrentCellChanged..this works and I can show in a listbox or console output...

However, I am wanting to place this in a datagrid dgMAIN...
can I do this?

My goal..have a datagrid with dept listing...i select dept 10 and get all the emps that have deptno = 10...i will then attempt to edit the children...

I hope this makes since...

====
Private Sub btnData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnData.Click
oOleDbConnection = New OleDb.OleDbConnection(sConnString)
oOleDbConnection.Open()
If ConnectionState.Open Then
TextBox1.Text = "Connection is made to Main"
TextBox1.BackColor = Color.Green
Else
TextBox1.Text = "Unable to make connection"
TextBox1.BackColor = Color.Red
End If

Dim strEMP, strDEPT As String
strEMP = "Select * from EMP"
strDEPT = "Select * from DEPT"

Dim daEMP = New OleDb.OleDbDataAdapter(strEMP, oOleDbConnection)
Dim daDEPT = New OleDb.OleDbDataAdapter(strDEPT, oOleDbConnection)
daEMP.Fill(ds, "EMP")
daDEPT.Fill(ds, "DEPT")
oOleDbConnection.Close()
dgDEPT.SetDataBinding(ds, "DEPT") 'to make sure table is obtained
dgEMP.SetDataBinding(ds, "EMP") 'to make sure table is obtained
'EXAMPLE OF MANUAL BINDING

custOrderRel = ds.Relations.Add("CustOrders", _
ds.Tables("DEPT").Columns("DEPTNO"), _
ds.Tables("EMP").Columns("DEPTNO"))


' Overload resolution failed because no accessible 'New' accepts this number of arguments..

' Add the relation to the DataSet.
'ds.Relations.Add(myDataRelation)
' GridOrders.SetDataBinding(ds, "Customers")
' GridDetails.SetDataBinding(ds, "Customers.CustOrd")


End Sub

======

Private Sub dgDEPT_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgDEPT.CurrentCellChanged

Dim r As DataRow
Dim intSum As Int32
Dim mike As String
TextBox1.BackColor = Color.Yellow

intSum = dgDEPT.CurrentRowIndex 'get Index of selected item in grid
mike = dgDEPT.Item(intSum, 0) 'get the value of the first column of the selected item

txtRowIndex1.Text = mike.ToString 'a check to make sure item is correct selection
ListBox1.Items.Clear() 'clear list box

For Each deptRow In ds.Tables("DEPT").Rows
If deptRow(0) = mike Then 'use to get only the select item value to use as relationship
'Console.WriteLine("Dept Table DEPTNO:" & deptRow("DEPTNO").ToString())

For Each empRow In deptRow.GetChildRows(custOrderRel)

ListBox1.Items.Add("ENAME: " + empRow("ENAME") + " MGR: " + empRow(3).ToString() + " DATE: " + empRow(4))
Next
End If
Next

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top