Reputation: 93
Firstly i would like to inform that I am quite new to C++/CLI programming and apologize if my question seems to be very basic. I have been searching the web for a solution the whole day but was unsuccessful.
I have a value struct which has another value struct as one of its data members. All the properties are displayed on the Propertygrid and are editable. But when I try to modify the property of the nested struct, the new value is not retained and it reverts back to 0 immediately. Why is this happening and how do I retain the value entered for the nested struct?
NOTE: I tried to comment out void set(nestedStruct value){ temp = value; } but still face the same issue.
[TypeConverter(ExpandableObjectConverter::typeid)]
public value struct nestedStruct
{
int z;
property int Z
{
int get() { return z; }
void set(int value) { z = value; }
};
};
public value struct parentStruct
{
int x;
property int X
{
int get() { return x; }
void set(int value) { x = value; }
};
int y;
property int Y
{
int get() { return y; }
void set(int value) { y = value; }
};
nestedStruct temp;
property nestedStruct Temp
{
nestedStruct get() { return temp; }
void set(nestedStruct value){ temp = value; }
};
};
Assigning to property grid:
parentStruct testStruct;
propertyGrid1->SelectedObject = testStruct;
propertyGrid1->ExpandAllGridItems();
Upvotes: 2
Views: 1455
Reputation: 93
I found this post under C# tag very helpful to solve the problem:
C# PropertyGrid: Changing properties not working?
I needed to override only the CanConvertFrom() from ExpandableObjectConverter.
public ref class MyExpandableObjectConverter : ExpandableObjectConverter
{
public:
virtual bool CanConvertFrom(ITypeDescriptorContext^ context, Type^ sourceType) override
{
if (sourceType == String::typeid)
return true;
else
return ExpandableObjectConverter::CanConvertFrom(context, sourceType);
}
};
and use the new type converter:
[TypeConverter(MyExpandableObjectConverter::typeid)]
public value struct nestedStruct
{
int z;
property int Z
{
int get() { return z; }
void set(int value) { z = value; }
};
};
Upvotes: 1