PC Review


Reply
Thread Tools Rate Thread

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

 
 
louisryder23
Guest
Posts: n/a
 
      17th Feb 2009
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.
 
Reply With Quote
 
 
 
 
louisryder23
Guest
Posts: n/a
 
      17th Feb 2009
Hi,

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.

Regards,
louis
 
Reply With Quote
 
Cor Ligthert[MVP]
Guest
Posts: n/a
 
      17th Feb 2009
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.


 
Reply With Quote
 
louisryder23
Guest
Posts: n/a
 
      18th Feb 2009
On Feb 17, 6:59*pm, "Cor Ligthert[MVP]" <Notmyfirstn...@planet.nl>
wrote:
> Louis,
>
> Take what you want
>
> http://www.vb-tips.com/dbpages.aspx?...aster%20detail
>
> Cor
>
> "louisryder23" <louisryde...@gmail.com> wrote in message
>
> news:be929710-7661-4d15-9c96-(E-Mail Removed)...
>


Thanks Cor !

The example code in :

" DataGridView: Master Detail grids using the bindingsource (without
the designer)"

worked really well for me.


Regards,
Louis R
 
Reply With Quote
 
louisryder23
Guest
Posts: n/a
 
      18th Feb 2009
On Feb 17, 6:59*pm, "Cor Ligthert[MVP]" <Notmyfirstn...@planet.nl>
wrote:
> Louis,
>
> Take what you want
>
> http://www.vb-tips.com/dbpages.aspx?...aster%20detail
>
> Cor
>
> "louisryder23" <louisryde...@gmail.com> wrote in message
>
> news:be929710-7661-4d15-9c96-(E-Mail Removed)...
>


Thanks Cor !

The example code in :

" DataGridView: Master Detail grids using the bindingsource (without
the designer)"

worked really well for me.


Regards,
Louis R
 
Reply With Quote
 
louisryder23
Guest
Posts: n/a
 
      18th Feb 2009
On Feb 17, 6:59*pm, "Cor Ligthert[MVP]" <Notmyfirstn...@planet.nl>
wrote:
> Louis,
>
> Take what you want
>
> http://www.vb-tips.com/dbpages.aspx?...aster%20detail
>
> Cor
>
> "louisryder23" <louisryde...@gmail.com> wrote in message
>
> news:be929710-7661-4d15-9c96-(E-Mail Removed)...
>


Thanks Cor !

The example code in :

" DataGridView: Master Detail grids using the bindingsource (without
the designer)"

worked really well for me.


Regards,
Louis R
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataGridViews, Master-Detail, Data-entry *and* Display louisryder23 Microsoft VB .NET 1 16th Feb 2009 11:06 AM
insert data into master detail entry form sugumar Microsoft VB .NET 1 1st Nov 2006 04:52 PM
Not too sure how to link master/child form when master is data entry graeme34 via AccessMonster.com Microsoft Access Form Coding 4 20th Mar 2006 01:27 PM
Hiccup in master-detail display =?Utf-8?B?Q29lbg==?= Microsoft VB .NET 2 20th Jan 2005 10:21 AM
how to create a master detail display on the datagrid Cecille Regidor Microsoft ADO .NET 2 4th Jan 2005 03:53 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:51 AM.