Knowledge Base

ShellBrowser .NET Components



Question / Problem

How can I prevent the selected path to be changed by the user?

Answer / Solution

Assign the PathChanged event for a ShellList and the BeforeSelect event for a ShellTreeView. If only want to allow the Windows folder, the code could look like this:


private const string cAllowedPath = "C:\\Windows";
private void shellListView1_PathChanged(object sender, EventArgs e)
{
 // Note: PathCollection also can check if the new Path is a subpath, by calling PathCollection.IsSubPathOf(string, string)
 if (!Jam.Shell.PathCollection.SamePath(shellListView1.Path, cAllowedPath))
  shellListView1.Path = cAllowedPath;
}


private void shellTreeView1_BeforeSelect(object sender, TreeViewCancelEventArgs e)
{
 if (!Jam.Shell.PathCollection.SamePath(((ShellTreeNode)e.Node)
.FullPath, cAllowedPath))
  e.Cancel = true;
}