I have implemented a master-detail form in VB 2005 with:
detailsview(to dsplay parent records)
datagridview (to display child records)
Everything works fine.......INSERT/DELETE/UPDATE, except one prb.
When i ADD a new PARENT record, the DATAGRIDVIEW doesn't clear and the old CHILD records still remain in the DATGIRDVIEW .
I want to clear the DATAGRID everytime a new parent record is created.
How do i do this ?
Creating master detail using wizard
add 2 dgv on a form, - yep u are using details, it is the same principle, just reach till the part where using and connecting the bindingsources, u will get it.
with the first dgv, click on the > on top and add data source.
select the parent table.
now with the second dgv, click on the > and do not select another table,
you will see the previous table selected name,. click on the + and select where you see FKthechildtablename.
thats it, add a navigator to control your parent table,. the work is done,
(part code generated)
'DataGridView1Me.DataGridView1.DataSource = Me.BillBindingSource
'DataGridView2 .DataGridView2.DataSource = Me.FKBillDetailedBillBindingSource
'BillBindingSource Me.BillBindingSource.DataMember = "Bill_" Me.BillBindingSource.DataSource = Me.CostingDataSet
Me.FKBillDetailedBillBindingSource.DataMember = "FK_Bill_Detailed_Bill_" Me.FKBillDetailedBillBindingSource.DataSource = Me.BillBindingSource
If you see the source of my child datasource, it is the parent;'s binding source.
If you got that, then the shortcut is in your data source window, set your parent s table as detailed view, drag and drop.
then under your parents table, you will see all child tables that are linked, set the child table to dgv view, drag and drop. work is done it is so simple
okay it should work, u do not have to clear child manually.
and if u have to build ur relationships manually , it is the same principle
Dimg1, g2 As New DataGridView Dim ds As New DataSet Dim t1, t2 As New DataTable Dim b1, b2 As New BindingSource
ds.Relations.Add(New DataRelation("FK_t2_t1", ds.Tables("t1").Columns("a1"), _
b1.DataSource = ds
b2.DataSource = b1
g1.DataSource = b1
g2.DataSource = b2
On my form, the master-detail relationships are working (INSERTING/DELETING/UPDATING) correctly. I have absolutely no prb with them. The only issue is when adding new records. When i click the ADD button from toolbar of PARENTBINDINGSOURCE, the DATAGRIDVIEW records dont CLEAR.
It only CLEARS when i click the SAVE BUTTON on the PARENTBINDINGSOURCE & generate a new record number.
So, is there any way to clear the DATAGRIDVIEW of old records, when i click the ADD button from toolbar of PARENTBINDINGSOURCE ??