How can I get OpenFileDialog in a custom control property grid?

I am creating a custom .net element and it should be able to upload multiple text files. I have a public ListLiles property with these properties:

[Browsable(true), Category("Configuration"), Description("List of Files to Load")] public string ListFiles { get { return m_oList; } set { m_oList = value; } } 

Depending on the type of object (line, line [], list, ...) the property grid allows the user to enter some data. My goal would be to have a filtered openfiledialog of my component in the property grid that allows the user to select multiple files and return them as an array or string (or something else ...).

Sooo ... Here is my question: How can I get OpenFileDialog in a custom control property grid?

Thank you so much!

+7
c # controls propertygrid
source share
3 answers

You can do this by adding a UITypeEditor .

Here is a UITypeEditor example that gives you an OpenFileDialog for a chossing filename.

+9
source share

You can use the built-in UITypeEditor. It is called FileNameEditor

 [EditorAttribute(typeof(System.Windows.Forms.Design.FileNameEditor), typeof(System.Drawing.Design.UITypeEditor))] public string SomeFilePath { get; set; } 
+11
source share

Here is another example of configuring File Dialog:

CustomFileEditor.cs

 using System.Windows.Forms; using System.Windows.Forms.Design; namespace YourNameSpace { class CustomFileBrowser : FileNameEditor { protected override void InitializeDialog(OpenFileDialog openFileDialog) { base.InitializeDialog(openFileDialog); openFileDialog.Title = "Select Project File : "; openFileDialog.Filter = "Project File (*.proj)|*.proj"; ; } } } 

Usage:

  [Category("Settings"), DisplayName("Project File:")] [EditorAttribute(typeof(CustomFileBrowser), typeof(System.Drawing.Design.UITypeEditor))] public string Project_File { get; set; } 
0
source share

All Articles