Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 678315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:08:10+00:00 2026-05-14T01:08:10+00:00

I have a FileNameEditor inside a property grid, which has a few entries like

  • 0

I have a FileNameEditor inside a property grid, which has a few entries like

Main File : “C:\blah1”

Sec File: “C:\blah2”

and so on.

My problem is that I cannot copy and paste from one property entry to another, and I cannot type in the fields manually as well. Is there a specific property that will enable editing inside the FileNameEditor.
Example

public class MyEditor : FileNameEditor
{
    public override bool GetPaintValueSupported(ITypeDescriptorContext context)
    {
        return false;
    }

    public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)

    {

        object e = base.EditValue(context, provider, value);

        if ((value as MyFileS) != null)
        {
            (value as MyFilesS).FileName = (String) e;
        }

        return e;
    }

    protected override void InitializeDialog(OpenFileDialog openFileDialog)
    {
        base.InitializeDialog(openFileDialog);
    }
}

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T01:08:10+00:00Added an answer on May 14, 2026 at 1:08 am

    Why are you using a custom editor? If you just want a string property on an object then Marc Gravell’s answer works.

    However if the “File” property on the object within the property grid is a custom class you also need to implement a custom type converter.

    Eg:

    namespace WindowsFormsApplication
    {
        using System;
        using System.ComponentModel;
        using System.Drawing.Design;
        using System.Globalization;
        using System.Windows.Forms;
        using System.Windows.Forms.Design;
    
        class MyEditor : FileNameEditor
        {
            public override bool GetPaintValueSupported(ITypeDescriptorContext context)
            {
                return false;
            }
    
            public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
            {
                string s = Environment.CurrentDirectory;
                object e = base.EditValue(context, provider, value);
                Environment.CurrentDirectory = s;
    
                var myFile = value as MyFile;
                if (myFile != null && e is string)
                {
                    myFile.FileName = (string)e;
                    return myFile;
                }
    
                return e;
            }
        }
    
        class MyFileTypeConverter : TypeConverter
        {
            public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
            {
                if (sourceType == typeof(string))
                    return true;
    
                return base.CanConvertFrom(context, sourceType);
            }
    
            public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
            {
                if (destinationType == typeof(string))
                    return true;
    
                return base.CanConvertTo(context, destinationType);
            }
    
            public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
            {
                if (value is string)
                    return new MyFile { FileName = (string)value };
    
                return base.ConvertFrom(context, culture, value);
            }
    
            public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
            {
                var myFile = value as MyFile;
                if (myFile != null && destinationType == typeof(string))
                    return myFile.FileName;
    
                return base.ConvertTo(context, culture, value, destinationType);
            }
        }
    
        [TypeConverter(typeof(MyFileTypeConverter))]
        [Editor(typeof(MyEditor), typeof(UITypeEditor))]
        class MyFile
        {
            public string FileName { get; set; }
        }
    
        class MyFileContainer
        {
            public MyFileContainer()
            {
                File1 = new MyFile { FileName = "myFile1.txt" };
                File2 = new MyFile { FileName = "myFile2.txt" };
            }
    
            public MyFile File1 { get; set; }
            public MyFile File2 { get; set; }
        }
    
        static public class Program
        {
            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main()
            {
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
    
                using (var f = new Form())
                using (var pg = new PropertyGrid())
                {
                    pg.Dock = DockStyle.Fill;
                    pg.SelectedObject = new MyFileContainer();
                    f.Controls.Add(pg);
                    Application.Run(f);
                }
            }
        }
    }
    

    To support editing the filename in place and also cut and paste the PropertyGrid needs to know how to convert from a string to your “File” type and back again. If you do not implement the convert to string methods in the TypeConverter the property will display the result of the object’s ToString().

    I suggest whipping out Reflector.Net and reading the source to some of the UITypeEditors and TypeConverters in the BCL as it can be quite informative to see how Microsoft supports editing Color, TimeSpan, DateTime etc in property grids.

    Also, be careful opening file dialogs. The standard WinForms open file dialog can change your applications current working directory if you’re not careful. I don’t think FileNameEditor has this problem, but I’ve only tested this under Windows 7.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a property grid control where I want to be able to display
Have you ever tried working with a XAML file which contains thousand tons of
Have the following scenario. I have a few form, which essentially have a few
Have just started using Visual Studio Professional's built-in unit testing features, which as I
Have you seen library for flexible working with terminal(Unix like)? I want to implement
have such zend query: $select = $this->_table ->select() ->where('title LIKE ?', '%'.$searchWord.'%') ->where('description LIKE
I have a snippet to create a 'Like' button for our news site: <iframe
I have a login.jsp page which contains a login form. Once logged in the
i have a input tag which is non editable, but some times i need
have tried a few different approaches to this but with no success so far.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.