How to display sub-object property in a DataGrid?

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.
 
D

Dmytro Lapshyn [MVP]

Michael,

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

Michael

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.
 

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