Datagridview and relation

E

Earl

I can write a bunch of code to use a datagridview with two related tables,
but I'm hoping to be able to use the bindingsources to do it instead. I'm
not getting any exceptions, but the datagridview is only displaying the
child columns instead of both the parent and child. What I'm doing is
setting up a strongly typed dataset, multiple bindingsources, merging data
into both tables (parent, then child) and then binding the relation to the
datagridview. Can anyone see where I'm going wrong?

Here is how I set it up in the visual designer:

1 strongly typed dataset (DSJOBS)
2 tables in the strongly typed with a relation/FK (Sales and JobSchedules)
1 datatagridview (dgv)
3 bindingsources:
SalesBindingSource (datasource = DsJobs; datamember = Sales)
ScheduleBindingSource (datasource = DsJobs; datamember = JobSchedules)
RelationBindingSource (datasource = SalesBindingSource; datamember =
FK_Sales_JobSchedules)

The code:
'this returns the PK and one other field
DsJobs.Sales.Merge(GetCurrentCustomersWithJobs())
'the FK here is related by SaleID to the Sales table, this returns all of
the JobSchedules table, including the FK
DsJobs.JobSchedules.Merge(GetJobSchedules)

'but the dgv ONLY displays the JobSchedules table
dgv.DataSource = RelationBindingSource
 
R

RobinS

The DGV doesn't display heirarchical data. To do that, use two DGV's, one
for the parent and one for the child. Bind the child's table to the FK.

Robin S.
 
E

Earl

I agree .. generally that is true. But you can bind a dgv to a relation. The
prototypical parent-dgv/child-dgv will not work for what I want to do. What
I've done instead (see my later question) was to go 4 deep on expression
columns. This allows me to create a single "hierarchical" datagridview
without the overhead of joins and the messiness of trying to do updates.
 
R

RobinS

Yes, I had seen your posting about the expression stuff, and thought it was
a neat solution. What *I* meant was you can't show it as heirarchical. I
don't know if you ever played with the Heirarchical Flex Grid in VB6, but
you could pass in a "shaped" query, and it would show the master records,
with a row of detail records, and you could open and close the sections. It
was really cool, and my customers loved it. That's it gone in DGV, but at
least you can do updates with DGV, which you had to do a lot of manual
gyrations to accomplish with the MSHFlexGrid in VB6. Phew. Makes me tired
just thinking of how much code I wrote to do that. Ugh.

Good luck.
Robin S.
-----------------------------------------
 

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

Top