IEnumerable interface

M

Mark

A class correctly implementing the IEnumerable interface can be bound to a
DataGrid or similar.

Let's say you have a class called Person, and it has fields like FirstName,
LastName and DateOfBirth, which are exposed as public properties. You
create a strongly typed collection class of Person objects that implements
the IEnumerable interface.

When you bind the collection class implementing IEnumeralbe to the DataGrid,
what events/methods/properties/whatever allow the DataGrid to know that it
should display the FirstName, LastName and DateOfBirth values from each
Person object in the DataGrid?

Thanks in advance.
Mark
 
N

Nicholas Paldino [.NET/C# MVP]

Mark,

In this case, the DataGrid is using reflection on each type to get the
properties to display.

However, you can control this. If you implement ITypedList on the list
object (the IList interface is what indicates it can be bound to, not
IEnumerable), then you can return the properties to be displayed through the
implementation of GetItemProperties.

You can even have the implementation return properties that don't exist
on the object. If the individual object implements ICustomTypeDescriptor,
then that object will be queried for properties and values.

Hope this helps.
 
M

Mark

** In this case, the DataGrid is using reflection on each type to get
the properties to display. **

Does it go after just the public properties, or internal/protected too?

You have way too much info packed away in that brain of your Nicholas.
Thanks again.

Mark

Nicholas Paldino said:
Mark,

In this case, the DataGrid is using reflection on each type to get the
properties to display.

However, you can control this. If you implement ITypedList on the list
object (the IList interface is what indicates it can be bound to, not
IEnumerable), then you can return the properties to be displayed through the
implementation of GetItemProperties.

You can even have the implementation return properties that don't exist
on the object. If the individual object implements ICustomTypeDescriptor,
then that object will be queried for properties and values.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Mark said:
A class correctly implementing the IEnumerable interface can be bound to a
DataGrid or similar.

Let's say you have a class called Person, and it has fields like
FirstName,
LastName and DateOfBirth, which are exposed as public properties. You
create a strongly typed collection class of Person objects that implements
the IEnumerable interface.

When you bind the collection class implementing IEnumeralbe to the
DataGrid,
what events/methods/properties/whatever allow the DataGrid to know that it
should display the FirstName, LastName and DateOfBirth values from each
Person object in the DataGrid?

Thanks in advance.
Mark
 
N

Nicholas Paldino [.NET/C# MVP]

Mark,

Just public properties. It wouldn't be playing too nicely if it just
disregarded the encapsulation that you determined for your class and exposed
private fields =)

Thanks for the compliment. I don't know that I can stuff anything else
in there, but I'm trying every day.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Mark said:
** In this case, the DataGrid is using reflection on each type to get
the properties to display. **

Does it go after just the public properties, or internal/protected too?

You have way too much info packed away in that brain of your Nicholas.
Thanks again.

Mark

in
message news:[email protected]...
Mark,

In this case, the DataGrid is using reflection on each type to get
the
properties to display.

However, you can control this. If you implement ITypedList on the list
object (the IList interface is what indicates it can be bound to, not
IEnumerable), then you can return the properties to be displayed through the
implementation of GetItemProperties.

You can even have the implementation return properties that don't exist
on the object. If the individual object implements
ICustomTypeDescriptor,
then that object will be queried for properties and values.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Mark said:
A class correctly implementing the IEnumerable interface can be bound to a
DataGrid or similar.

Let's say you have a class called Person, and it has fields like
FirstName,
LastName and DateOfBirth, which are exposed as public properties. You
create a strongly typed collection class of Person objects that implements
the IEnumerable interface.

When you bind the collection class implementing IEnumeralbe to the
DataGrid,
what events/methods/properties/whatever allow the DataGrid to know that it
should display the FirstName, LastName and DateOfBirth values from each
Person object in the DataGrid?

Thanks in advance.
Mark
 

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