Datagrid binding to a business object property

Datagrid binding to a business object property

Old forum URL: forums.lhotka.net/forums/t/3640.aspx


Pieterv posted on Wednesday, October 03, 2007

Hi All,

I have a OrderLine BusinessBase object, and a Product BusinessBase object.

The Orderline object has a property Product, which is a Product Object.
I can load and create the ordeline easy enough with the product object included, and binding the Product.Description proeprty to a textbox is very simple.

The problem I have is binding to datagrid. The Product column shows the product object's ID.

What would be the correct way to parse/interpret the product object to either show the product ID and product.description property or only the description property on the product object in the datagrid?

I hope I'm clear enough.

Thanks!


RockfordLhotka replied on Wednesday, October 03, 2007

Almost certainly what is happening here is that data binding is seeing the Product property as a complex type, so it calls ToString() to get a value from it that can be displayed. The default ToString() is your id value. But you can override ToString() to return a description or something else.

Pieterv replied on Thursday, October 04, 2007

Thank you Rocky.

It works like a charm!

Copyright (c) Marimer LLC