The blog has moved to a new address. The blog is now located at http://devintelligence.com

Sunday, February 04, 2007

Propertygrid: How to show only specific file extensions?

 

Use Editor Attribute

 

[DisplayName("Resume")]
[Description(
"Resume File Name")]
[Editor(
typeof(DocFileEditor), typeof(UITypeEditor))]
public string ResumeFile
{
get
{
return _ResumeFile;
}
set
{
_ResumeFile
= value;
}
}

 


 


Override InitializeDialog method and provide Filter string that describes allowed file extensions



using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.Design;

namespace WindowsApplication1
{
class DocFileEditor : FileNameEditor
{
///<summary>
///Initializes the open file dialog when it is created.
///</summary>
///
///<param name="openFileDialog">The <see cref="T:System.Windows.Forms.OpenFileDialog">
</see> to use to select a file name. </param>
protected override void InitializeDialog(OpenFileDialog openFileDialog)
{
openFileDialog.CheckFileExists
= false;
openFileDialog.Filter
= "Doc files (*.doc)|*.doc|All files (*.*)|*.*";

}
}
}