This is a migrated thread and some comments may be shown as answers.

How to correctly set the datagridview datacontext

1 Answer 136 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ivan
Top achievements
Rank 1
Ivan asked on 07 Jan 2009, 07:43 PM
Hello!
Let's say I have this class :

class Person
{
public Address address;
public DateTime age;

...
Ctor's and so on ...

}

class Address
{
string street;
int number;

...
}

And suppose that I have a datagrid, inside a wpf grid where I set the datacontext to a list of Persons like this :

personGrid.datacontext = personDao.getAll() as List<Person>;

What I want to know is how i define what will appear in Address column. I know i can do this overriding the toString() method on Address class, but I want to do something like "DisplayMemberPath = "street" . Is that possible ?

Thanks,
Ivan Frias

1 Answer, 1 is accepted

Sort by
0
Nedyalko Nikolov
Telerik team
answered on 09 Jan 2009, 12:19 PM
Hello Ivan,

Yes it is possible.
Take a look at our demo examples. The one called "Data Binding" and the kind of the data is "PropertyPaths". See the code behind for details how to do this. You can set these properties from xaml as well.

P.S.
You almost guest the name of the property it is "DataMemberPath" instead of "DisplayMemberPath".

Best wishes,
Nedyalko Nikolov
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
GridView
Asked by
Ivan
Top achievements
Rank 1
Answers by
Nedyalko Nikolov
Telerik team
Share this question
or