Skip to content

Preselect a directory and populate it on startup #7

@AFract

Description

@AFract

Hello Chris,
I am using your control since a very long time in an old project, I have just tried to update it from the original CodeProject version to this Github enhanced edition (my final goal is to migrate it to .Net 7.0, it works great so far except for a few details).
So thanks a lot for your great work !

Here's my problem, In the old version, it was easy to "preselect" a folder on startup on show its content directly.
I want to have "Desktop" as root, and jump directly to a specific folder and expand it. I did this :

            var datasource = new TreeViewFolderBrowserDataProviderShell32();
            datasource.EnableContextMenu = true;
            datasource.ShowAllShellObjects = true;

            ctlFolderSelect.DriveTypes = DriveTypes.All;
            ctlFolderSelect.DataSource = datasource;
            ctlFolderSelect.RootFolder = Environment.SpecialFolder.Desktop;

            ctlFolderSelect.Populate(@"C:\"); // For example

With the new version, I get an ArgumentOutOfRangeException, by doing something close (I have slightly adapted my old code to attempt to match updated version) :

            var datasource = new TreeStrategyShell32Provider();
            datasource.EnableContextMenu = true;
            datasource.ShowAllShellObjects = true;
            
            ctlFolderSelect.CheckBoxBehaviorMode = CheckBoxBehaviorMode.None;
            datasource.DriveTypes = DriveTypes.All;
            ctlFolderSelect.DataSource = datasource;

            ctlFolderSelect.Populate(@"C:\"); // Throws ArgumentOutOfRangeException

When I open manually the folders in the control, everything works great.

Could you please tell me how to preselect a folder and expand it by code ? I didn't see any example of this in the "Demo" project and I found nothing by my own.

Thanks a lot

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions