hide public property in propertygrid

J

J-L

Hi,

I have a class with a public property that I don't want to display in
ma propertygrid.

Is is an attribute to hide this property ?

J-L
 
T

Tom Shelton

Hi,

I have a class with a public property that I don't want to display in
ma propertygrid.

Is is an attribute to hide this property ?

J-L

I believe if you apply the BrowseableAttribute set to false to the
property, then it won't show in the property grid:

[Browsable(false)]
public in MyProperty{get;set;}

HTH
 
J

J-L

Il se trouve que Marc Gravell a formulé :
[Browsable(false)]

Marc

Thanks a lot Marc, I have found this after :).

While you are here, can you help me a little ?
In propertygrid, I use Filenameeditor to display windows dialog box.
Is it another editor but to choose a directory ?

J-L
 
C

Ciaran O''Donnell

Assuming you mean a control which has a runtime only property, then apply the
following attribute to the property:

[System.ComponentModel.DesignTimeVisibleAttribute(false)]
 
M

Marc Gravell

FolderNameEditor, as in:

[Editor(typeof(FolderNameEditor), typeof(UITypeEditor))]

However, I notice that it loses the existing value when you hit the
[...] (i.e. it doesn't start at the current folder). I hastily cobbled
the following together, which does that, and also uses the Description
etc to set a suitable caption...

Marc

public class Foo
{
[Description("Where does it go?")]
[Editor(typeof(MyFolderNameEditor), typeof(UITypeEditor))]
public string Bar { get; set; }
}

public class MyFolderNameEditor : UITypeEditor
{
public override UITypeEditorEditStyle
GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.Modal;
}
public override object EditValue(ITypeDescriptorContext context,
IServiceProvider provider, object value)
{
string path = Convert.ToString(value);
using (FolderBrowserDialog dlg = new FolderBrowserDialog())
{
if (!string.IsNullOrEmpty(path) && Directory.Exists(path))
{
dlg.SelectedPath = path;
}
if (context != null && context.PropertyDescriptor != null)
{
// pick [Description], [DisplayName] or Name in that
order
string caption =
context.PropertyDescriptor.Description;
if (string.IsNullOrEmpty(caption))
{
caption = context.PropertyDescriptor.DisplayName;
}
if (string.IsNullOrEmpty(caption))
{
caption = context.PropertyDescriptor.Name;
}
dlg.Description = caption;
}
if (dlg.ShowDialog() == DialogResult.OK)
{
path = dlg.SelectedPath;
}
}
return path;
}
}
 

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