DataGridViews, Master-Detail, Data-entry *and* Display




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")
If blnNewTransactionEntry Then 'if in Data entry
mode ie. from New transaction)
' ??? WHAT GOES HERE ???
Else 'if in Display mode
(ie. from Search results)
Catch ex As Exception
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


' 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
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
against the selected master record. When I navigate back to the
first master record, it should display in the detail grid the records
I entered previously against this master record.

This implies that some kind of filter should display the records from
detail datatable - but how can it be done?

If someone who has done this could point the way, it would be much

Thanks in advance,
Louis R.



I figured that I can use the Filter property on the detail
bindingsource in combination with a CellContentClick event on the
master grid to achieve the behavior that I need.

But, does anyone know how it can be done automatically without using a
Filter / Cellcontent click combination ie. using a datarelation ?
Note that my situation is unique in that I am using the same grids for
display and then later for data-entry, so I need to be able to
'switch' between the two.


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question