displaying string-array elements as read-only (grayed) in propertygrid

K

Ken Snyder

hi all!

how can i display a string array as read only inside
a property grid? i do have a custom object that holds
a property of kind string[]. the problem is that the
string array itself is made "ReadOnly(true)" by attribte
assigned to it, but its elemnts are still displayed non
grayed and read/write, so the user can alter the string
inside it. but i wont that! how can the string elements
made be readonly?

thanks in advance.

kr

ken
 
M

Morten Wennevik [C# MVP]

Hi Ken,

You will have to display them your own way with a custom property editor or
fake the property using a display property and hide the real property

private string[] _data = new string[] { "Some", "String", "Values" };

[ReadOnly(true)]
public string Data { get { return string.Join(Environment.NewLine, _data); } }
[Browsable(false)]
public string[] RealData { get { return _data; } set { _data = value; } }
 
M

Morten Wennevik [C# MVP]

Hi Ken,

You will have to display them your own way with a custom property editor or
fake the property using a display property and hide the real property

private string[] _data = new string[] { "Some", "String", "Values" };

[ReadOnly(true)]
public string Data { get { return string.Join(Environment.NewLine, _data); } }
[Browsable(false)]
public string[] RealData { get { return _data; } set { _data = value; } }
 

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