This is a migrated thread and some comments may be shown as answers.

FolderBrowserDialog in PropertyGrid

4 Answers 583 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Artem
Top achievements
Rank 1
Artem asked on 09 Dec 2012, 09:15 AM
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

4 Answers, 1 is accepted

Sort by
0
Artem
Top achievements
Rank 1
answered on 12 Dec 2012, 08:41 AM
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)
0
Accepted
Ivan Petrov
Telerik team
answered on 12 Dec 2012, 05:40 PM
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.
0
Aref
Top achievements
Rank 1
answered on 20 Nov 2017, 06:43 PM
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 
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 21 Nov 2017, 01:36 PM
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.
Tags
PropertyGrid
Asked by
Artem
Top achievements
Rank 1
Answers by
Artem
Top achievements
Rank 1
Ivan Petrov
Telerik team
Aref
Top achievements
Rank 1
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or