Search:
Namespaces
Discussions
.NET v1.1
Feedback
IEnumerable interface
Messages
Related Types
This message was discovered on
microsoft.public.dotnet.languages.csharp
.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...
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
Reply to this message...
Nicholas Paldino [.NET/C# MVP] (VIP)
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]
-
Click here to reveal e-mail address
"Mark" <
Click here to reveal e-mail address
> wrote in message
news:%
Click here to reveal e-mail address
...
[Original message clipped]
Reply to this message...
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 [.NET/C# MVP]" <
Click here to reveal e-mail address
> wrote in
message news:
Click here to reveal e-mail address
...
[Original message clipped]
Reply to this message...
Nicholas Paldino [.NET/C# MVP] (VIP)
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]
-
Click here to reveal e-mail address
"Mark" <
Click here to reveal e-mail address
> wrote in message
news:%
Click here to reveal e-mail address
...
[Original message clipped]
Reply to this message...
System.Collections.IEnumerable
System.Collections.IList
System.ComponentModel.ICustomTypeDescriptor
System.ComponentModel.ITypedList
System.Web.UI.WebControls.DataGrid
System.Windows.Forms.DataGrid
Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us
-
Terms of Use
-
Privacy Policy
-
www.dotnet247.com