PropertyGrid.SelectedObject

How may I force PropertyGrid to work?

Actually - I'm displaying PropertyGrid, but I can't force it to display any properties.

There is

PropertyGrid.SelectedObject

property. That property should be set to the object which properties we want to display.

I have a class:

__gc class Person
{
private:
int id;
public:
void set_id (int n);
int get_id ();
};

and what I do is:

// Person* pPerson has already been created
PropertyGrid.SelectedObject = pPerson;

But no properties are displayed...
I know it is too simple to work - there should be probably some interface implemented or something... But I don't know exactly - since MSDN doesn't give any clue.

AFAIK similar code in CSharp (without implementing any interfaces or anything) would probably work.
But in Man C++ - it doesn't.

Please help!

Thanks in advance.
[991 byte] By [Janeko] at [2007-11-18 13:39:34]
# 1 Re: PropertyGrid.SelectedObject
Hi,
I'm posting an answer almost a year and a half later.
Sorry for the delay. :-)

In C++, the class you create must use the __property keyword.

For example.

using namespace System::ComponentModel;
using namespace System;

public __gc class SimpleProperties {
private:
bool trueOrFalse;
String* aString;
String* bString;
public:
SimpleProperties() {
aString = new String("hello");
bString = new String("bye");
}
[CategoryAttribute("Category1"), DefaultValueAttribute(true)]
__property bool get_TrueOrFalse() {
return trueOrFalse;
}
__property void set_TrueOrFalse(bool value) {
trueOrFalse = value;
}
[CategoryAttribute("Category1"),
DescriptionAttribute("A string is a string is a string")]
__property String* get_AString() {
return aString;
}
__property void set_AString(String* value) {
aString = value;
}
[CategoryAttribute("Category2")]
__property String* get_BString() {
return bString;
}
__property void set_BString(String* value) {
bString = value;
}
};

There is also a nice website about the propertygrid for C# programmers that can be ported to C++.
http://msdn.microsoft.com/vcsharp/programming/classlibraries/default.aspx?pull=/library/en-us/dndotnet/html/usingpropgrid.asp

Good luck
toiletman at 2007-11-9 12:02:06 >