monkeydluffy
monkeydluffy

Reputation: 229

Explorer in Treeview

enter image description here

how to do this in Treeview control? I'm using C#, I do some research but it is so very difficult to get only the desktop... I can get the logical drivers, but I need to get "DESKTOP" only and it will expand to show "My Documents", "My Computer" and other items that can see in my desktop.

Upvotes: 1

Views: 1881

Answers (1)

AvkashChauhan
AvkashChauhan

Reputation: 20576

Try this:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace DesktopTreeView
{
 public partial class Form1 : Form
 {
    public Form1()
    {
        InitializeComponent();
        LoadFoldersInTreeView(treeView1);
    }

    void LoadFoldersInTreeView(TreeView treeName)
    {
        treeName.BeginUpdate();
        treeName.Nodes.Add("Desktop");
        DirectoryInfo dirInfo = new DirectoryInfo(@"C:\");
        TreeNode node = new TreeNode();
        node.Text = "My Computer";
        treeName.Nodes[0].Nodes.Add(node);
    }
 }
}

And results are shows as below:

enter image description here

Upvotes: 3

Related Questions