creating a form that will display all the properties of an object

  • Thread starter Thread starter JJ L.
  • Start date Start date
J

JJ L.

Hello.

I have a project that consists of nine different objects, each serving
their own purpose. In the past I have just created a form for each
one, and then whenever you call, say, object.Display(), it would call
up the form associated with that object. This form only displays
information, it doesn't allow the user to edit any information. Is it
possible to find the properties of a certain object, and then loop
through creating labels and such for every property? I believe I've
heard the Reflection class mentioned somewhere, but from what I see in
the MSDN library, it may not be exactly what I'm looking for. I also
only want to display the properties I defined.

Thank you,
JJ L.
 
JJ,

In order to do this, you would have to use reflection. You would use
reflection to get the property names, and then create UI elements that are
linked to those properties on the instance of the object you have.

An easier alternative would be to use the PropertyGrid class, which does
all of this for you.

Hope this helps.
 
JJ L,

Reflection is exactly what you are after. Reflection is not a class it is
method for discovering inforamtion of objects and classes at run time as
well as dynamically creating objects and executing methods. If you want to
discover all the proerties and get their values of objects you know nothing
about Reflection is exactly what you need.

Look at
Object.GetType method and/or C# typeof operator
Type class
Type.GetProperties method
PropertyInfo class

If you need something like VS property browser, you have it out of the box.
Look at PropertyGrid component.
 

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

Back
Top