Datagrid - binding child property

G

Guest

Hi,
I am binding a collection of "Orders" to a datagrid and I want to display
"Product.Description" to a column, product being a member of Order class.

Code:
DataGridTextBoxColumn productColumn = new DataGridTextBoxColumn();
productColumn.MappingName = "Product.ID";
productColumn.HeaderText = "Product";
tableStyle.MappingName = "SalesOrderProduct";
ProductLineGrid.TableStyles.Add(tableStyle);
productLineGrid.DataSource = _orders;

Classes:
class Order
{
public OrderProduct Product
{
get;
}
....
}

class OrderProduct
{
public string Description
{
get;
}
....
}

Binding a column to "Product.Desctription" does not seem to work. Is there a
way to bind property of a child tho the grid?

Thanks,
Rakesh
 
I

Ilya Tumanov [MS]

That is not supported on NETCF and I doubt that is supported on a desktop.



You can either expose all the properties of OrderProduct on Order class or
you can override painting and access whatever data you want.

In last case your columns are still created for properties of Order class
but you can retrieve and print whatever you want in your custom code.



My advice: drop all these messy custom classes and collections and use
DataSet with computed columns to flatten the hierarchy.

Your code would be reduces probably tenfold with little to no impact on
performance or memory usage - you keep data in memory anyway.


--
Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.

*** Want to find answers instantly? Here's how... ***

1. Go to
http://groups-beta.google.com/group/microsoft.public.dotnet.framework.compactframework?hl=en
2. Type your question in the text box near "Search this group" button.
3. Hit "Search this group" button.
4. Read answer(s).
 
R

Rak

Thanks a lot Ilya.

I have exposed the property in the parent class.

I value your advice, but in my case I have a middle layer ormlayer that we
use for persistance and so it will be an overhead to convert the business
objects to dataset and back.

Thanks,
Rakesh
 

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