FolderBrowserDialog in PropertyGrid

5 posts, 1 answers
  1. Artem
    Artem avatar
    16 posts
    Member since:
    May 2013

    Posted 09 Dec 2012 Link to this post

    Hi,
    In my application I use RadPropertyGrid and I create set of properties for it in my code using RadPropertyStore.

    Before I started to use RadPropertyGrid all properties were displayed in group-boxes with different controls like text-box, drop-down and button. It was a mess.
    One of the properties should contain path to some local directory. And in old implementation it was displayed by text box and browse button that was opening FolderBrowserDialog 
    .
    As you might already imagine, my question is how can I insert FolderBrowserDialog to RadPropertyGrid?
    What I have managed to do is below:
        public partial class SettingsManager : UserControl
        {
            public SettingsManager()
            {
                InitializeComponent();
                _propertyStore = CreateProperties();
                radPropertyGrid1.SelectedObject = _propertyStore;
                radPropertyGrid1.PropertySort = PropertySort.CategorizedAlphabetical;
            }
            private RadPropertyStore _propertyStore;
            private PropertyStoreItem _defaultSaveDirectory;
     
            private RadPropertyStore CreateProperties()
            {
                var result = new RadPropertyStore();
                _defaultSaveDirectory = new PropertyStoreItem(typeof(string),
                                                            "DefaultSaveFolder",
                                                            Properties.Settings.Default.DefaultSaveFolderPath,
                                                            "Default directory for saving snapshot and configuration files.",
                                                            "Save Snapshot/Configuration",
                                                            false);
                _defaultSaveDirectory.PropertyChanged += OnDefaultSaveDirectoryChanged;
                result.Add(_defaultSaveDirectory);
                return result;
            }
     
            void OnDefaultSaveDirectoryChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
            {
                var folderDialog = new FolderBrowserDialog {
                                                               Description = Resources.DefaultLocationDialogHelp,
                                                               ShowNewFolderButton = true
                                                           };
     
                if (DialogResult.OK == folderDialog.ShowDialog())
                {
                    _defaultSaveDirectory.PropertyChanged -= OnDefaultSaveDirectoryChanged;
                    _defaultSaveDirectory.Value = folderDialog.SelectedPath;
                    _defaultSaveDirectory.PropertyChanged += OnDefaultSaveDirectoryChanged;
                    Properties.Settings.Default.DefaultSaveFolderPath = folderDialog.SelectedPath;
                }
            }
    }

    But I have two problems with this implementation:
    1) FolderBrowserDialog opens on initialization
    2) There is no such a thing like Click event for PropertyStoreItem, so user have to really change the property value in order to FolderBrowserDialog to appear

  2. Artem
    Artem avatar
    16 posts
    Member since:
    May 2013

    Posted 12 Dec 2012 Link to this post

    Sorry, guys :)
    I have found the solution in this thread:
    Property editor displays a dialog


    It describes how to add button to text editor of string property. I just modified the click event handler to open FolderBrowserDialog and that is it :)
    Thanks for great control (RadPropertyGrid)
  3. Answer
    Ivan Petrov
    Admin
    Ivan Petrov avatar
    701 posts

    Posted 12 Dec 2012 Link to this post

    Hello Artem,

    Thank you for writing.

    The approach you have found is one way to go. The other is to use the already available in RadPropertyGrid PropertyGridBrowseEditor. All you have to do is subscribe to the EditorRequired event and change the editor. Here is a code snippet:
    private void radPropertyGrid1_EditorRequired(object sender, PropertyGridEditorRequiredEventArgs e)
    {
      PropertyGridBrowseEditor editor = new PropertyGridBrowseEditor();
      RadBrowseEditorElement element = editor.EditorElement as RadBrowseEditorElement;
      element.DialogType = BrowseEditorDialogType.FolderBrowseDialog;
      e.Editor = editor;
    }

    I hope this will help. Feel free to write back with any further questions.
     
    All the best,
    Ivan Petrov
    the Telerik team
    Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
  4. Aref
    Aref avatar
    20 posts
    Member since:
    Sep 2015

    Posted 1 day and 19 hours ago Link to this post

    Dear Telerik team
    I am wondering if there is any way to change the folder browser dialog texts to localize it's items.
    Sincerely yours 
    Aref 
  5. Dess
    Admin
    Dess avatar
    2174 posts

    Posted 1 day ago Link to this post

    Hello, Aref,

    Thank you for writing.  

    PropertyGridBrowseEditor internally uses the standard MS FolderBrowserDialog. The dialog displays text using the standard dialog on Windows. There is no appropriate API for localizing it. 

     Should you have further questions I would be glad to help.
     
    Regards,
    Dess
    Progress Telerik
    Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top