tags:

views:

24

answers:

3

Hi,

I am retrieving info from a web service and saving it in a class which has several fields including arrays.

I just want a way to present that info to the user. Is there a component that takes the class as argument and just organizes the info and shows them in a datagridview (for example)?

Thank you.

A: 

you use reflection for this issues find out more about this on google.

one of the demo :

static void Main(string[] args)
        {
            object obj = new Employee();
            Type t = obj.GetType();

            try
            {
                System.Reflection.PropertyInfo minfo = t.GetProperties().First(m => m.Name == "ABC");
                Console.WriteLine(minfo.Name);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Member not found");
            }
            Console.ReadLine();
        }

another example :

protected void setControl(Object obj)
{
    Type t = obj.GetType();
    foreach (System.Reflection.PropertyInfo minfo in t.GetProperties())
    {
        try
        {

            string s  = (minfo.GetValue(obj, null)).ToString();
        }
        catch (Exception ex)
        {
            Console.WriteLine("Member not found");
        }
    }
}
Pranay Rana
That looks like it just grabs a particular property off the class if it exists - can you use Reflection to walk over a class you don't know the layout of, and include all the properties?
rwmnau
this just demo i want to show , see the another code it will work
Pranay Rana
A: 

Since the response is serializable, you could probably map it pretty easily to something like a TreeView as well. Even though you have a class as your response object, and you can use Reflection to walk over it, I'd probably serialize it and then walk through the XML, though I suppose it's just a point of preference.

rwmnau
A: 

If you're just looking for a way to display the properties of your class to the user, you might try the PropertyGrid (http://msdn.microsoft.com/en-us/library/aa302326.aspx).

It allows for a simple representation of common datatypes, but also allows you to add custom representation if you need it.

At its simplest, you just need to set the object you want represented:

            propertyGrid1.SelectedObject = myObject;
Ragoczy