Property Grid question (simple?)

S

sb

Consider the following example code:
....
namespace MyNamespace
{
public class MyClass
{
private int m_Count;

[TypeConverter(typeof(ExpandableObjectConverter))]
public int Count
{
get { return m_Count; }
set { m_Count= value; }
}

// ....etc...
}
}

When setting a PropertyGrid's SelectedObject to an instance of this class,
it shows "MyNamespace.MyClass"...can I change that so that it displays
something more user friendly? It just looks tacky and I'd like to fix it :)

Any tips would be appreciated!

TIA
-sb
 
J

Jon Shemitz

sb said:
namespace MyNamespace
{
public class MyClass
When setting a PropertyGrid's SelectedObject to an instance of this class,
it shows "MyNamespace.MyClass"...can I change that so that it displays
something more user friendly? It just looks tacky and I'd like to fix it :)

The short answer is Yes.
Any tips would be appreciated!

The long(er) answer is that this is sort of complicated, and that
there are samples online. Try Googling - you'll find plenty.

--

..NET 2.0 for Delphi Programmers <http://www.midnightbeach.com/.net>

Delphi skills make .NET easy to learn
Just printed, and shipping now.
 
S

sb

I did try googling...but I used the wrong terms. Anyway, I figured it out:
public sealed class MyExpandableObjectConverter : ExpandableObjectConverter
{
public override object ConvertTo(ITypeDescriptorContext context,
System.Globalization.CultureInfo culture, object value, Type
destinationType)
{
return "MyName";
}
}

Not that tough after all.

Thanks.
-sb
 
S

sb

Thanks! That's even simpler...now I feel dumb since I shoulda known that :)

-sb

JJ said:
By default, PropertyGrid calls ToString() to display this value.

You can simply override the ToString() function in MyClass to return your
friendly value.

Good Luck
Jeff http://www.ruamkwamkid.com

sb said:
Consider the following example code:
...
namespace MyNamespace
{
public class MyClass
{
private int m_Count;

[TypeConverter(typeof(ExpandableObjectConverter))]
public int Count
{
get { return m_Count; }
set { m_Count= value; }
}

// ....etc...
}
}

When setting a PropertyGrid's SelectedObject to an instance of this
class, it shows "MyNamespace.MyClass"...can I change that so that it
displays something more user friendly? It just looks tacky and I'd like
to fix it :)

Any tips would be appreciated!

TIA
-sb
 

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

Top