none
master-detail form. CHILD records in DATAGRIDVIEW doesn't clear on adding new PARENT record

    Question

  • Hi all,

     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 ?

    Alex

     

     

     

    Thursday, October 12, 2006 9:43 PM

All replies

  • 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)

    'DataGridView1

    Me.DataGridView1.DataSource = Me.BillBindingSource

    'DataGridView2

    .DataGridView2.DataSource = Me.FKBillDetailedBillBindingSource

    'BillBindingSource

    Me.BillBindingSource.DataMember = "Bill_"

    Me.BillBindingSource.DataSource = Me.CostingDataSet

    'FKBillDetailedBillBindingSource

    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

    Dim g1, g2 As New DataGridView

    Dim ds As New DataSet

    Dim t1, t2 As New DataTable

    Dim b1, b2 As New BindingSource

    t1.TableName = "t1"

    t2.TableName = "t2"

    t1.Columns.Add(New DataColumn("a1"))

    t2.Columns.Add(New DataColumn("b1"))

    ds.Tables.Add(t1)

    ds.Tables.Add(t2)

    'Relevant code

    ds.Relations.Add(New DataRelation("FK_t2_t1", ds.Tables("t1").Columns("a1"), _

    ds.Tables("t2").Columns("a1")))

    b1.DataMember = "t1"

    b1.DataSource = ds

    b2.DataMember = "FK_t2_t1"

    b2.DataSource = b1

    g1.DataSource = b1

    g2.DataSource = b2

     

    Friday, October 13, 2006 6:16 AM
  • Hi hrubesh,

                  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 ??

    Alex.

    Friday, October 13, 2006 8:11 AM
  • I do not know, I thought this problem would be because master-detail was not set properly,

    i do not have a  problem with any of my master details done as explained above:

    Could you please let know how ur bindings are done/relationships too.

    Wednesday, October 18, 2006 7:23 AM