Expand 'This PC' node on view opening

Shell for WPF Forum

Posted 4 years ago by Dowse - UK
Version: 19.1.0685
Avatar

Hello

When setting the RootSpecialFolderKind="Default" property on a ShellTreeListBox I get the folder list I require but would like the 'This PC' node to be expanded when the view is displayed. 

Have tried reviewing the sample apps/code, and setting a breakpoint in my code and inpecting the ShellListTree object,  but still not really sure how to progress. Programmatically expanding the node? DataFilter,(if that's what they can be used for)? Something else? 

As a 'Joe-coder' rather than a 'Pro-coder' any advice would be most welcome, preferably with a line or 2 of code, to get me pointed in the right direction.

Many thanks

[Modified 4 years ago]

Comments (3)

Posted 4 years ago by Dowse - UK
Avatar

After a bit more research I came up with:

for (int i = 0; i < listbox.Items.Count; i++)
{
    ShellObjectViewModel item = (listbox.Items[i] as ShellObjectViewModel);

    if (item.Name == "This PC")
    {

        item.IsExpanded = true;
        break;
    }
}

It's not very elegant but it get's the job done.

If you have a more 'compact' solution I would be most grateful to see it.

Thank you.

Answer - Posted 4 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

This is probably a better way.  You can make a custom class that inherits our ShellObjectItemAdapter class, and override this method:

protected override ShellObjectViewModel CreateShellObjectViewModel(TreeListBox ownerControl, IShellObject shellObject) {
	var viewModel = base.CreateShellObjectViewModel(ownerControl, shellObject);

	if (shellObject.SpecialFolderKind == SpecialFolderKind.Computer)
		viewModel.IsExpanded = true;

	return viewModel;
}

Then set an instance of that class to the ShellTreeListBox.ItemAdapter property, and it should work.


Actipro Software Support

Posted 4 years ago by Dowse - UK
Avatar

Thank you.

Just what I was looking for.

The latest build of this product (v24.1.3) was released 3 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.