Louis,
Take what you want
http://www.vb-tips.com/dbpages.aspx?...aster%20detail
Cor
"louisryder23" <(E-Mail Removed)> wrote in message
news:be929710-7661-4d15-9c96-(E-Mail Removed)...
> Hi,
>
> I need to do data-entry as well as display in two datagridview that
> are setup as Master-Detail. They are linked to BindingSources whose
> datatables are filled from another tier (class).
>
> I have the display part working fine ie. if you click in the master
> grid, the relevant records appear in the detail grid. This is done
> using the CellContentClick of the master grid.
>
> Here is my code for the CellContentClick event:
>
> Private Sub dgvMasterGrid_CellContentClick....
> If (dgvMasterGrid.Columns(e.ColumnIndex).Name = "Description")
> Then
> If blnNewTransactionEntry Then 'if in Data entry
> mode ie. from New transaction)
> '
> ' ??? WHAT GOES HERE ???
> '
> Else 'if in Display mode
> (ie. from Search results)
> Try
> bolTransaction.FillDetails(bsDetails,
> dgvMasterGrid.Rows(e.RowIndex).Cells(0).Value)
> Catch ex As Exception
> MsgBox(ex.Message)
> End Try
> End If
> End If
>
> After this executes, the detail grid is filled the required details.
>
> Now, my problem is - I need to do data entry, in the detail grid (only
> the detail grid) against fixed rows in the master grid. I have
> already got the datatables linked to the bindingsources set-up as
> master-detail. I haven't figured out how to get the detail grid to
> display *only* the related records for the selected row in the master
> grid, when a row in the master grid is clicked. I haven't found any
> code examples anywhere either demonstrating how this could be
> achieved. Considering that I have already set-up the master-detail,
> then shouldn't it automatically display the related records in the
> detail grid? Or do I have to call some specific function on the
> binding source??
>
> This is the code that I have to set-up the master-detail:
>
> With bolTransaction
> .FillMaster(bsMaster, 0)
> .FillDetail(bsDetail, 0)
> End With
>
> bsMaster.AddNew()
> bsMaster.EndEdit()
>
> ' when populating first time, then default the MasterID column
> to autonumbers
> '(if there are errors later, check this one )
> CType(bsMaster.DataSource, DataTable).Columns
> ("MasterID").AutoIncrement = True
> CType(bsMaster.DataSource, DataTable).Columns
> ("MasterID").AutoIncrementSeed = 1
>
> '----used for master-detail relation when Entering new
> transaction
> Dim ds As New DataSet
> ds.Tables.Add(CType(bsMaster.DataSource, DataTable))
> ds.Tables.Add(CType(bsDetail.DataSource, DataTable))
>
> Dim dr As New DataRelation("master-detail", _
> CType(bsMaster.DataSource, DataTable).Columns("MasterID"), _
> CType(bsDetail.DataSource, DataTable).Columns("MasterID"))
>
> CType(bsDetail.DataSource, DataTable).ParentRelations.Add(dr)
>
> blnNewTransactionEntry = True
>
>
>
> Note that the detail grid will be empty during data-entry, I will be
> entering new records. This is fine for the first master record, but
> I want it such that when I navigate to the next master record in the
> master grid, it should clear the detail grid and allow to enter
> records
> against the selected master record. When I navigate back to the
> first master record, it should display in the detail grid the records
> that
> I entered previously against this master record.
>
> This implies that some kind of filter should display the records from
> the
> detail datatable - but how can it be done?
>
>
>
>
> If someone who has done this could point the way, it would be much
> appreciated.
>
>
>
>
>
> Thanks in advance,
> Louis R.