PropertyGrid - can't edit property

  • Thread starter Thread starter julia_beresford
  • Start date Start date
J

julia_beresford

Hi

I have a main class with a public property of type sub class, which
has several properties of type int.

When i assign an instance of my main class to
propertyGrid.SelectedObject I cannot edit values for the properties of
my sub class, I can't even expand it (I was expecting to see the
little + sign next to it, to expand the int properties). Can anyone
tell me how to do this please.

Many thanks
Julia.
 
I had looked in to this, and below is my implementation, which still
doesn't work. What else am i missing?

Many thanks
Julia.

public class Class1
{
private MySize m_size;

public MySize Size
{
get
{
return m_size;
}
set
{
m_size = value;
}
}
}

[TypeConverter(typeof(ExpandableObjectConverter))]
public class MySize
{
private int m_x;
private int m_y;

public int X
{
get
{
return m_x;
}
set
{
m_x = value;
}
}
public int Y
{
get
{
return m_y;
}
set
{
m_y = value;
}
}
}
 
What else am i missing?
obj.Size = new Size();

The Size is null; depending on the scenario, it may be prudent for the
Class1 ctor to create a Size, perhaps as "readonly". If the Size is
immutable (common if it is a struct, which "Size" often is), then note
that the converter can still support editing sub-properties via
CreateInstance() [can explain if needed]. Likewise, if you want the
user to be able to edit the Size string directly
(rather/in-addition-to than the sub-properties), then your converter
must support ConvertFrom for string.

Marc
 

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