all groups > dotnet windows forms databinding > december 2004 >
You're in the

dotnet windows forms databinding

group:

Binding to a related column


Binding to a related column Oleg Ogurok
12/15/2004 11:39:14 PM
dotnet windows forms databinding: Hi all,

I have a strongly typed dataset with tables:
Users: ID, First Name, LastName
Orders: ID, Quantity, UserID

UserID is related to Users' ID column via a DataRelation.

I'm binding Orders table to a DataGrid, and one of the columns I need to be
the First+Last name of the corresponding user.
How can I accomplish it?

I tried adding a DataGridColumnStyle and setting MappingProperty to bunch of
different values but none worked.

Also, any tutorials on DataGrid are gladly appreciated.
Thanks.
-Oleg.

Re: Binding to a related column Ritesh Jain via DotNetMonster.com
12/16/2004 3:54:56 PM
Hi ,
In ur User Table add one more DataColumn and Use Table.column("New Col").Expression="First Name + LastName"

and than bind ur datagird with new NEw column.

i hope this is what u want..........

Ritesh

--
Re: Binding to a related column Nicolas L.
12/19/2004 4:29:25 PM
Users table is in a relation 1-to-many with Orders, so if you want to add
First and Last Name of Users to Orders,
you could add one more DataColumn to table Orders and set the expression to:

Dim dcFullName As DataColumn

' Create the column.
dcFullName = New DataColumn
With dcFullName
.DataType = System.Type.GetType("System.String")
.ColumnName = "FullName"
.Expression = "Parent.FirstName + Parent.LastName"
End With

myDataSet.Table("Orders").Columns.Add(dcFullName)

Don't forget to include the "Parent." in the expression because you're
referring a parent table from its child, to refer a child from its parent
you must antepone "Child." to the column name. For a complete use of
DataColumn.Expression Property go to:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatadatacolumnclassexpressiontopic.asp

Nicolas L.

"Oleg Ogurok" <oleg@ogurok.com.ihatespammers.ireallydo.co> escribió en el
mensaje news:10s24epfut03vfe@corp.supernews.com...
[quoted text, click to view]

Re: Binding to a related column csdk
1/29/2005 3:43:01 PM
This is an interesting solution. I would like to ask also ... if I had many
related columns from multiple tables that I wold like to bind to and display
on the same form, would it be better to define and attach the new columns
at design time (in the dataset xsd) or at runtime inside that form?
Thanks

[quoted text, click to view]
AddThis Social Bookmark Button