How to display sub-object property in a DataGrid?

  • Thread starter Thread starter Michael
  • Start date Start date
M

Michael

I have two classes, say A and B. Class A has a property of type B. For
example:
class A
int ID
B SubObject

class B
string Name

I bind my DataGrid to class A. I want to display B's Name property.

I have code like:
DataGridTextBoxColumn col1 = new DataGridTextBoxColumn();
col1.MappingName = "SubObject.Name"; // this does not work

How to I tell the DataGrid to display a property from a sub-object of class
A?

I saw this question asked a few times on the Net, but never had an answer.
Maybe it's not even possible...

Thanks.
 
Michael,

How about a simple workaround - introduce a public R/O property on A that
would simply return B.Name.
 
Thanks Dmytro.


Dmytro Lapshyn said:
Michael,

How about a simple workaround - introduce a public R/O property on A that
would simply return B.Name.

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]


Michael said:
I have two classes, say A and B. Class A has a property of type B. For
example:
class A
int ID
B SubObject

class B
string Name

I bind my DataGrid to class A. I want to display B's Name property.

I have code like:
DataGridTextBoxColumn col1 = new DataGridTextBoxColumn();
col1.MappingName = "SubObject.Name"; // this does not work

How to I tell the DataGrid to display a property from a sub-object of
class A?

I saw this question asked a few times on the Net, but never had an
answer. Maybe it's not even possible...

Thanks.
 
Back
Top