venkataramanaiahsr
asked on
Programatically Updating Bound child datagridview
I have two DataGridViews on a form in a parent-child relationsihp. The parent dgv is bound to a BindingSource whose DataSource is a table. The child dgv is bound to a BindingSource whose DataSource is the parent BindingSource and whose DataMember is the relation between the parent and child tables in the DataSet.
Parent Grid (dgvOEntryAdvise)
bindingsource11.DataSource = dsDet.Tables("OIAdviseDeta ils")
dgvOEntryAdvise.DataSource = bindingsource11
Child Grid ( dgvOSAdvise)
bindingsource13.DataSource = bindingsource11 'dsDet.Tables("OSAdviseDet ails") '
bindingsource13.DataMember = "FK_OS_OI_Advise"
dgvOSAdvise.DataSource = bindingsource13
dtOEntry = dsDet.Tables("OIAdviseDeta ils") --
table bound to parent dgv (dgvOEntryAdvise)
Dim newrow As DataRow = dtOEntry.NewRow()
newrow.BeginEdit()
newrow("Caseid") = lngcaseid
newrow("OCCode") = dgvOIList.CurrentRow.Cells ("Occode") .Value
newrow("OCName") = dgvOIList.CurrentRow.Cells ("OCName") .Value
newrow("OICode") = dgvOIList.CurrentRow.Cells ("OICode") .Value
newrow("OIName") = dgvOIList.CurrentRow.Cells ("OIName") .Value
newrow.EndEdit()
dtOEntry.Rows.Add(newrow)
(Upto this it is working fine)
for some order item in parent grid i want to add programatically few child rows in the child datagrid ...
Pls advise on how to do this
Parent Grid (dgvOEntryAdvise)
bindingsource11.DataSource
dgvOEntryAdvise.DataSource
Child Grid ( dgvOSAdvise)
bindingsource13.DataSource
bindingsource13.DataMember
dgvOSAdvise.DataSource = bindingsource13
dtOEntry = dsDet.Tables("OIAdviseDeta
table bound to parent dgv (dgvOEntryAdvise)
Dim newrow As DataRow = dtOEntry.NewRow()
newrow.BeginEdit()
newrow("Caseid") = lngcaseid
newrow("OCCode") = dgvOIList.CurrentRow.Cells
newrow("OCName") = dgvOIList.CurrentRow.Cells
newrow("OICode") = dgvOIList.CurrentRow.Cells
newrow("OIName") = dgvOIList.CurrentRow.Cells
newrow.EndEdit()
dtOEntry.Rows.Add(newrow)
(Upto this it is working fine)
for some order item in parent grid i want to add programatically few child rows in the child datagrid ...
Pls advise on how to do this
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I have no objection against what you said but it isn't a solution. If at the first place you can combine two relationship into one row display, then this question does not stand. There's a reason to have master detail. Imagine one master record can have 30 rows of details, show them in one grid??
ASKER
I could solve it by other means. i got the both parent and child data into single grid by join
statement and it solved my problem
statement and it solved my problem
I don't know why you wish to add rows but you can only add them to the binding source and rebind the child datagridview.