How to support editing file path properties in the properties window

Hello,

I've implemented a simple property page by extending SettingsPage. One of my custom properties is a string that representes a file path, like so:

[Category("Test")]

[Description("Path to a test file")]

[DisplayName("Test File path")]

public string MyFilePath

{

get {returnthis.myFilePath; }

set {this.myFilePath=value; this.IsDirty = true; }

}

How do I support the editing of this file path property beyond a simple text string?

I'm trying to emulate the editing capability of a property such as the "Working Directory" property from a C++ project's Debugging configuration properties group. In this case the Working Directory property can be edited in place as a string or via a drop down menu which has a "<Browse>..." and an "<Edit>..." item for browsing and editing a file path. How can I implement this type of capability for my custom property?

Many thanks!

Eric

[1770 byte] By [EricHsieh] at [2007-12-16]
# 1
Hi Eric,
The .NET Framework types use the TypeConverter and UITypeEditor classes to provide most of the PropertyGrid editing support. I believe you can use FileNameEditor attribute with the MyFilePath property as shown below.

[EditorAttribute(typeof(FileNameEditor), typeof(System.Drawing.Design.UITypeEditor))]
[Category("Test")]
[Description("Path to a test file")]
[DisplayName("Test File path")]
public string MyFilePath
{
get { return this.myFilePath; }
set { this.myFilePath= value; this.IsDirty = true; }
}

For more information see the following topics on customizing property grid.

ms-help://MS.MSDNQTR.v80.en/dndotnet/html/vsnetpropbrow.htm
ms-help://MS.MSDNQTR.v80.en/dndotnet/html/usingpropgrid.htm

Hope that helps.
Dr. eX

Dr.eX at 2007-9-9 > top of Msdn Tech,Visual Studio,Visual Studio Extensibility...

Visual Studio

Site Classified