Using PropertyGrid

M

MFRASER

How can I override the editor that populates a property in the propertygrid?

I want to have my property set by the FileDialog.

Here is a sample of my code.

[Editor("System.Windows.Forms.FileDialog",
"System.Drawing.Design.UITypeEditor")]

[Browsable(true)]

/// <summary>

/// Get XMLDataFile

/// </summary>

public string XMLDataFile

{

get{return @m_Path;}

set{setXMLPath(value);}

}
 
B

Bob Powell [MVP]

A

Arne Janning

Hi MFRASER!

How can I override the editor that populates a property in the
propertygrid?

I want to have my property set by the FileDialog.

Here is a sample of my code.

[Editor("System.Windows.Forms.FileDialog",
"System.Drawing.Design.UITypeEditor")]

[Browsable(true)]

/// <summary>

/// Get XMLDataFile

/// </summary>

public string XMLDataFile

{

get{return @m_Path;}

set{setXMLPath(value);}

}

There is a built-in System.Windows.Forms.Design.FileNameEditor for you. As a
UITypeEditor, you can attach it to the property with EditorAttribute. The
code will look like

[Editor(typeof(System.Windows.Forms.Design.FileNameEditor),
typeof(System.Drawing.Design.UITypeEditor))]
public string YourFileNameProperty
{
.....
}

For other type of properties, you can use other build-in UITypeEditor, or
write your own UITypeEditor.

Here is a good article that explains how to do this:
http://msdn.microsoft.com/library/en-us/dndotnet/html/usingpropgrid.asp

Cheers

Arne Janning
 
F

Fraser Michael

I am not able to run the code.
[EditorAttribute(typeof(System.Windows.Forms.Design.FileNameEditor),
typeof(System.Drawing.Design.UITypeEditor))]

The system can not locate the FileNameEditor, I have the
System.Windows.Forms.dll
System.Design.dll
System.Windows.Design.dll

and I still can't locate the editor. What assembly contains the
FileNameEditor?
 
A

Arne Janning

Hi Michael!

I am not able to run the code.
[EditorAttribute(typeof(System.Windows.Forms.Design.FileNameEditor),
typeof(System.Drawing.Design.UITypeEditor))]

The system can not locate the FileNameEditor, I have the
System.Windows.Forms.dll
System.Design.dll
System.Windows.Design.dll

System.Windows.Design.dll ? Doesn't exist.
and I still can't locate the editor. What assembly contains the
FileNameEditor?

Add a reference to System.Drawing.dll and System.Design.dll.

The following code works for me:

string test;

[Editor(typeof(System.Windows.Forms.Design.FileNameEditor),
typeof(System.Drawing.Design.UITypeEditor))]
public string Test
{
get
{
return test;
}
set
{
test = value;
}
}

The FileNameEditor-Class is defined in namespace System.Windows.Forms.Design
and is implemented in System.Design.dll.
The UITypeEditor-Class is defined in namespace System.Drawing.Design and is
implemented in System.Drawing.dll.

Cheers

Arne Janning
 

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