The FolderBrowser control can only be started in one of the predefined "special" folders. I wanted it to start in the current folder. Here is an example of how to do that:
First, add a FolderBrowserCallback event handler to the FolderBrowser object. Then add the following code specifying the directory you want the folder to open:
using System.Runtime.InteropServices;
/*...*/
[DllImport("user32.dll",CharSet=CharSet.Unicode)]
public static extern UInt32 SendMessage( IntPtr hWnd, UInt32 Msg, UInt32 wParam, IntPtr lParam);
private void folderBrowser1_FolderBrowserCallback(object sender, Syncfusion.Windows.Forms.FolderBrowserCallbackEventArgs e)
{
if (e.FolderBrowserMessage==FolderBrowserMessage.Initialized)
{
const int BFFM_SETSELECTIONW=1127;
SendMessage(e.Window.Handle,BFFM_SETSELECTIONW,1,Marshal.StringToHGlobalUni(@"c:\temp"));
}
}
ED
Eric Duesing
August 8, 2003 05:14 AM
Actually, that leaks, doesn't it. Instead of this:
>SendMessage(e.Window.Handle,BFFM_SETSELECTIONW,1,Marshal.StringToHGlobalUni(@"c:\temp"));
Try This:
IntPtr p=Marshal.StringToHGlobalUni(@"c:\temp");
SendMessage(e.Window.Handle,BFFM_SETSELECTIONW,1,p);
Marshal.FreeHGlobal(p);
RP
Ramesh Praveen
Syncfusion Team
August 11, 2003 07:21 AM
Eric,
Thanks for the info! That's a big help, it's been a frequent feature request. We will log this in our KB.
-Praveen
ME
Mark Emerson
August 26, 2003 04:43 PM
Eric,
Thank you! I've been wanting the ability to set a start location in the .NET world for sometime and hated using the old VB6 controls within wrappers. Excellent!
Mark
MS
Martin Schacher
October 11, 2005 10:52 AM
Is there a workaround for vb to set the initial-directory?
>Eric,
>
>Thank you! I''ve been wanting the ability to set a start location in the .NET world for sometime and hated using the old VB6 controls within wrappers. Excellent!
>
>Mark
AR
Anupama Roy
Syncfusion Team
October 13, 2005 03:57 AM
Hi Martin,
The following features for FolderBrowser have been added to our build internally.
1) Enumeration value
FolderBrowserFolder.CustomStartLocation for Folder.StartLocation property.
2) FolderBrowserFolder.CustomStartLocation property for dialog root path.
3) FolderBrowserFolder.SelectLocation property for automatic scroll and highlight of desired path.
Which version of Syncfusion are you using now?
Best Regards,
Anu.