RE: Display mutliple 1-1 tables in DataGrid?
- From: "Kelly Sumrall" <KellySumrall@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 10 Jun 2005 12:44:10 -0700
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)
>
>
.
- Follow-Ups:
- RE: Display mutliple 1-1 tables in DataGrid?
- From: tbrummel
- RE: Display mutliple 1-1 tables in DataGrid?
- References:
- Display mutliple 1-1 tables in DataGrid?
- From: tbrummel
- Display mutliple 1-1 tables in DataGrid?
- Prev by Date: Display mutliple 1-1 tables in DataGrid?
- Next by Date: Re: Can't read some excel cell into ADO.NET
- Previous by thread: Display mutliple 1-1 tables in DataGrid?
- Next by thread: RE: Display mutliple 1-1 tables in DataGrid?
- Index(es):
Relevant Pages
|