Articles in this section
Category / Section

How to customize WinForms MultiCoulumnTreeView like FileExplorer?

1 min read

Customize the MultiColumnTreeView

In MultiColumnTreeView, you can load the files as you load in File Explorer, by using DriveInfo, DirectoryInfo class and by handling NodeMouseDoubleClick event. The following code example is used to get the files from directories.

C#

//To get directory
DriveInfo drive = new DriveInfo(e.Node.Text);
DirectoryInfo dir = drive.RootDirectory;
//To get all files
foreach (FileInfo fi in dir.GetFiles())
{
    TreeNodeAdv item = new TreeNodeAdv(fi.Name);
    item.ShowPlusMinus = false;
    e.Node.Nodes.Add(item);
}
//To open selected files
void multiColumnTreeView1_NodeMouseDoubleClick(object sender, MultiColumnTreeViewAdvMouseClickEventArgs e)
{
    if (e.Node.Text.Contains("."))
        System.Diagnostics.Process.Start(e.Node.FullPath);
}

VB

'To get directory
Dim drive As New DriveInfo(e.Node.Text)
dir = drive.RootDirectory
'To get files
For Each fi As FileInfo In dir.GetFiles()
    Dim item As New TreeNodeAdv(fi.Name)
    item.ShowPlusMinus = False
    e.Node.Nodes.Add(item)
Next fi
'To open selected files
Private Sub multiColumnTreeView1_NodeMouseDoubleClick(ByVal sender As Object, ByVal e As MultiColumnTreeViewAdvMouseClickEventArgs)
    If e.Node.Text.Contains(".") Then
       System.Diagnostics.Process.Start(e.Node.FullPath)
    End If
End Sub

The following screenshot illustrates the output.

Files loaded as loaded in File explorer

Figure 1: Files loaded as loaded in File Explorer

Sample: https://www.syncfusion.com/downloads/support/directtrac/general/MultiColumnTreeView_Folderbrowser1165728106.zip

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied