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

RadBrowseEditor that accepts file OR directory

5 Answers 368 Views
BrowseEditor
This is a migrated thread and some comments may be shown as answers.
sebastien
Top achievements
Rank 1
sebastien asked on 29 Nov 2018, 04:46 PM

Hi,

I'm in a need for a dialog form that in the end returns a FilePath OR a DirectoryPath, with a TextBox that the user can paste something (file or directory).

I tried doing so with a System.Windows.Forms.FolderBrowserDialog but without success.

 

I'm turning over Telerik, found the RadBrowseEditor and calling the RadBrowseEditor .BrowseElement.BrowseButton.PerformClick() method for opening.

The best/closest DialogType is BrowseEditorDialogType.OpenFileDialog, but the problem is when pasting a DirectoryPath, the control navigates there and no event is raised (same as the system's FolderBrowserDialog, it's even the same used from Telerik).

I tried listening to events ValueChanging and also all those under the BrowseElement object, but nothing works.

 

Any idea (I didn't want to create a new form, developping the navigation treeview, textbox, since almost everyhing is there)?

 

thanks

5 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 30 Nov 2018, 01:10 PM
Hello, Sebastien,    

If I understand your requirement correctly, you are trying to paste a file path to the editable part of a RadBrowseEditor and when you click the "..." button to open the dialog with the pasted path preselected. For this purpose, you can set the Value property of RadBrowseEditor:
public RadForm1()
{
    InitializeComponent();
 
    this.radBrowseEditor1.DialogType = BrowseEditorDialogType.OpenFileDialog;
    this.radBrowseEditor1.ReadOnly = false;
    this.radBrowseEditor1.Value = @"D:\Projects\1363202 VirtualGridCellClick\RadForm1.cs";
}

Note that you can manipulate the dialog and apply some filter for example. The OpenFileDialog can be accessed by the BrowseElement.Dialog property: 

private void RadForm1_Load(object sender, EventArgs e)
{
    OpenFileDialog dialog = this.radBrowseEditor1.BrowseElement.Dialog as OpenFileDialog;
    dialog.Filter = "Solution Files|*.sln";
}

The below code snippet demonstrates how you can show the dialog programmatically and extract the selected file after the dialog is closed:

private void RadForm1_Load(object sender, EventArgs e)
{
    OpenFileDialog dialog = this.radBrowseEditor1.BrowseElement.Dialog as OpenFileDialog;
 
    if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
    {
        this.Text = dialog.FileName;
    }
}

I hope this information helps. If you need any further assistance please don't hesitate to contact me.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
sebastien
Top achievements
Rank 1
answered on 30 Nov 2018, 02:19 PM

Hi Dess, I used all of what you mentioned without answering my needs :(

Attached is an FolderBrowserDialog, that's the closest thing I've found.

With that kind of dialog form the user can select a FolderPath but I need ALSO to be able to select a file.

At least, adding a textbox like in the attachment where a path can be pasted would work.

Do you have any form/tool that I can start with or inherit from?

 

thank you Dess

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 03 Dec 2018, 11:17 AM
Hello, Sebastien,    

RadBrowseEditor uses the Windows Forms FolderBrowserDialog component when the DialogType property is set to FolderBrowseDialog. It is a modal dialog box that is used for browsing and selecting folders. For selecting files, feel free to set the DialogType property to OpenFileDialog. There is no dialog which allows selecting both, folders and files simultaneously.

However, you can create a derivative of the RadBrowseEditorElement and override its  OnBrowseButtonClick method. Thus, you have the option to initialize and show your custom dialog with the exact design that you wish to achieve. Here is demonstrated a sample code snippet demonstrating how to plug the dialog in RadBrowseEditor:

public class CustomBrowseEditor : RadBrowseEditor
{
    public override string ThemeClassName 
    {
        get
        {
            return typeof(RadBrowseEditor).FullName; 
        }
    }
 
    protected override RadBrowseEditorElement CreateEditorElement()
    {
        return new CustomRadBrowseEditorElement();
    }
}
 
public class CustomRadBrowseEditorElement : RadBrowseEditorElement
{
    protected override Type ThemeEffectiveType    
    {
        get   
        {
            return typeof(RadBrowseEditorElement);    
        }
    }
 
    protected override void OnBrowseButtonClick(EventArgs e)
    {
        //initialize and show your own custom dialog
        base.OnBrowseButtonClick(e);
    }
}

Feel free to extend it and implement the custom requirement that you have.

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Should you have further questions please let me know.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
sebastien
Top achievements
Rank 1
answered on 03 Dec 2018, 02:30 PM

Thank you Dess, but that doesn't answer my needs.

I'm now convinced that I'll have to do my own FolderAndFileBrowserDialog.

I was trying with the RadBrowseEditor but in real it'll be from a RadButtonElement in a menu.

At least we tried!

0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 04 Dec 2018, 11:10 AM
Hello, Sebastien,    

Unfortunately, there is no universal dialog for selecting folders and files. That is why there are two separate dialogs for these purposes. However, in my previous reply, there was demonstrated a sample approach how you can plug into the browse button's Click event where you can create a custom dialog for achieving your custom requirement.

As to the RadButtonElement, you can directly handle its Click event and show the custom dialog that you construct for selecting the folder and files simultaneously.

Should you have further questions please let me know.

Regards,
Dess | Tech Support Engineer, Sr.
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
BrowseEditor
Asked by
sebastien
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
sebastien
Top achievements
Rank 1
Share this question
or