RE: Display mutliple 1-1 tables in DataGrid?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hmm. Not good.

First off, I do not have multiple children and the data is text so there is
no aggregate function that I can use in referencing the child item.

What I'd like to be able to do is set the DataGrid.DataSource = myDataSet
(which contains both tables) and then set up the grid columns like this:

Grid.Column[0].DataTable = "Customers"
Grid.Column[0].DataItem = "Name"
Grid.Column[1].DataTable = "CustomerNotes"
Grid.Column[1].DataItem = "Note"

Sadly, I don't think anyone thought of this when the DataGrid was being
developed.

So, the workaround (solution, I guess) I came up with is to add the columns
from table to the schema for table1 and then .Merge the second table into the
first so I end up with one table for the DataGrid. Then, when I need to save
the table 2 data, I take the table being displayed and delete the table1
schema (columns) from it and then write it. Works like a charm since both
tables use the same primary key and I never need to save table 1 (it's
static). Seems like a hack but I think writing a display control that
handled multiple tables/items would be more work :-)

Thanks


"Kelly Sumrall" wrote:

> I don't believe you are going to be able to do it the way your are
> explaining. You are wanting to set the DataGrid.DataSource = Table, right? To
> get this to work, you are going to have to modify one of the tables to
> contain a DataColumn with an Expression pointing to the other tables column
> of interest.
> TableA (A DataColumns)
> TableB (B DataColumns)(A Expression DataColumns)
>
> Here is a quote from the MSDN DataColumn.Expression property documentation:
> PARENT/CHILD RELATION REFERENCING
>
> A parent table may be referenced in an expression by prepending the column
> name with Parent. For example, the Parent.Price references the parent table's
> column named Price.
>
> A column in a child table may be referenced in an expression by prepending
> the column name with Child. However, because child relationships may return
> multiple rows, you must include the reference to the child column in an
> aggregate function. For example, Sum(Child.Price) would return the sum of the
> column named Price in the child table.
>
> If a table has more than one child, the syntax is: Child(RelationName). For
> example, if a table has two child tables named Customers and Orders, and the
> DataRelation object is named Customers2Orders, the reference would be:
> Avg(Child(Customers2Orders).Quantity)
>
>
> if you are using typed DataSets, this can be done using the GUI interface.
>
> Not a magical solution, but one that is solved by a lot of typing.
>
> "tbrummel" wrote:
>
> > I’ve read a number of article/books on ADO.NET and the DataGrid and nobody
> > seems to address displaying multiple tables at once (not master/detail).
> >
> > I’ve got two tables that have a 1-1 relationship based on a primary key.
> > Basically, think of it as one logical record (Customer) with some data in
> > table 1 and other data in table 2. I have these loaded into a DataSet and I
> > have a relation defined between them.
> >
> > However, I cannot find any way to make the DataGrid display data from both
> > tables at the same time. I want to see the following:
> >
> > Name Address
> > John 663 Main
> > Sally 223 Oak
> > …
> >
> > Where Name is coming from table 1 and Address is coming from table 2.
> >
> > Is this possible with the DataGrid control(s)? (I can certainly look at
> > writing a custom display control but I’d hate to reinvent the wheel)
> >
> >
.



Relevant Pages

  • Re: how to concatenate a number to a variable name?
    ... That I can understand and might give it consideration if I were designing the ... I would hesitate to go with a child table though for each ... used for multiple products with a variety of configuration possibilities, ... Doug Steele, Microsoft Access MVP ...
    (microsoft.public.access.modulesdaovba)
  • Re: Multiple Instances of Application
    ... So move the basic code for your UI child application into a shared assembly ... have to go with the multiple exe copies approach for now. ... the parking window class name. ... So, if your child processes are data processing bits, not UI bits, this ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Hideing Uneeded Fields in a form Via Check Box?
    ... Well it was more for reducing the cluter on the form it self, ... majority of the time having multiple pick up and drop off address listed will ... But there are times when a client needs product picked up a multi address ... Also the child tables I create a relationship with the host via ID, ...
    (microsoft.public.access.formscoding)
  • Re: Bad mommy or cultural difference?
    ... sometimes it leads to rude behaviors), ... My oldest child is a bit like this ... With multiple children with occasionally ... different from the first two lately in making the point that Kids Are Different ...
    (misc.kids)
  • Re: Can an RTSTRUCT have more than one information set per series?
    ... but multiple distinct image series. ... (many RTSTRUCTs referencing one image series) ... to multiple image sets (one RTSTRUCT referencing many image series). ... relative to that volume, between slices slices, or spanning slices ...
    (comp.protocols.dicom)