.NETGURU
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




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification