First of All i would Thank this forum. Most of my programming queries were solved here. I dint had to write any new thread..
I am new to windows Application programing. but i am some how managing ..
But now i need a start to do something like .

If any one has ideas or have done it before please help me out..
Thank You your time.

Dani AI

Generated

A few focused, practical fixes based on the thread so far: 's split-container idea (TreeView + ListView) is the right layout. The two concrete issues shown in the replies are (A) parent/child checkbox propagation and (B) hiding virtual/special shell items (Control Panel, Recycle Bin, etc.). The approach in Post #8 (filtering by the SHGetFileInfo type string) works but is fragile because type names vary by OS language and shell extensions. Prefer structural checks instead.

To propagate checks reliably, suppress the AfterCheck handler while you set child states and use a small recursive helper. This prevents the handler from re-entering and only performs one traversal:

bool _suppressAfterCheck;

private void treeView1_AfterCheck(object sender, TreeViewEventArgs e)
{
    if (_suppressAfterCheck) return;

    try
    {
        _suppressAfterCheck = true;
        SetChildrenChecked(e.Node, e.Node.Checked);
    }
    finally
    {
        _suppressAfterCheck = false;
    }
}

private void SetChildrenChecked(TreeNode node, bool isChecked)
{
    foreach (TreeNode n in node.Nodes)
    {
        n.Checked = isChecked;
        SetChildrenChecked(n, isChecked);
    }
}

To avoid virtual items under "My Computer", do not rely on display-type text. If you only want real volumes, enumerate drives via System.IO.DriveInfo.GetDrives() and filter by DriveType (Fixed, Removable, CDRom). Example:

foreach (var d in DriveInfo.GetDrives())
{
    if (d.IsReady && d.DriveType == DriveType.Fixed)
        treeView1.Nodes.Add(new TreeNode(d.Name) { Tag = d.RootDirectory.FullName });
}

If you must enumerate shell PIDLs, test whether the PIDL maps to a filesystem path (for example via SHGetPathFromIDList or IShellItem2::GetDisplayName(SIGDN_FILESYSPATH)); if that call fails, skip the item. Additional tips: call treeView.BeginUpdate()/EndUpdate() during bulk changes, lazy-load child nodes on Expand, catch UnauthorizedAccessException/PathTooLongException when touching the filesystem, and run heavy enumerations on a background thread and marshal UI updates back to the UI thread. These practices avoid flicker, keep the UI responsive, and are more robust than filtering by localized type names.

Recommended Answers

All 7 Replies

I would start a forms application and put a splitcontainercontrol in it.
In Panel1 I would put a TreeView control in Panel2 I would try a ListView.

commented: Perfectly answered :D +6

Thank You ddanbe..
Now :
1)
how to make all the child node checked when parent node is checked. i tried this but only first 2 child nodes get checked.. here's what i tried.

private void treeView1_AfterCheck(object sender, TreeViewEventArgs e)
        {                 
            //MessageBox.Show(e.Node.Level.ToString());
            
            //MessageBox.Show(e.Node.Nodes.Count.ToString());
            if (e.Node.Checked)
            {
                int n = e.Node.Level;
                TreeNode a = new TreeNode();
                a = e.Node;
                MessageBox.Show(a.Index.ToString());
                if (a.Nodes.Count != 0)
                    a.FirstNode.Checked = true;
                else
                {
                    if (a.Index <= a.Nodes.Count)
                    {
                        a = a.NextNode;
                        if (a != null)
                            a.Checked = true;
                    }
                    else
                    {
                        a = a.Parent.NextNode;
                        if (a != null)
                            a.Checked = true;
                    }

                }

            }
        }

Am I totally wrong here?

2) how to bring the system directory's in tree view.

Thank You Very Much Antenka.. I dint realize it was so easy LoL..
Thank You ddanbe & Antenka Again for Your Time..

Okay..
how do i make the control pannel , Recycle Bin ,Cd drive's not listed in the treeview..
any idea..

Hello, jobi116.
As one of the solutions, I can offer this to you:
there is one function : SHGetFolderPath (shell32), that can help you get the path to 'special' folders, like you are listed. you can find much more such folders.
Also there is some class in .Net, that allows you to get path to some of that folders: Environment.SpecialFolder Enumeration.

So all you have to do - catch the 'special' folder and do not add it into your treeview.

P.S. I had some troubles getting the path to the Control Panel, so if you'll get something like that - we'll invent something else ;) Good luck.

P.P.S. If you want to investigate more in using shell, look here:

C# does Shell, Part 2
C# does Shell, Part 3

Thank You Again Ankenta..
I did go through the links..
and i added ShellAPI.SHGFI.SHGFI_TYPENAME for vflags..

ShellAPI.SHFILEINFO shInfo = new ShellAPI.SHFILEINFO();
            ShellAPI.SHGFI vFlags =
                ShellAPI.SHGFI.SHGFI_SMALLICON |
                ShellAPI.SHGFI.SHGFI_SYSICONINDEX |
                ShellAPI.SHGFI.SHGFI_PIDL |
                ShellAPI.SHGFI.SHGFI_DISPLAYNAME |
                ShellAPI.SHGFI.SHGFI_TYPENAME ;

            ShellAPI.SHGetFileInfo(m_pIDL, 0, out shInfo,             (uint)Marshal.SizeOf(shInfo), vFlags);

Now i can get the type of the Shellitem ..
That is Control Pannel, My Documents are of type System Folder.
and Cd Drives are of Type CD Drives, And HD Partition were of Type Local Disk..
Since i wanted My Computer node to List only HD Partition i added an condition before creating node.

foreach (ShellItem shChild in arrSub)
{
if (((ShellItem) e.Node.Tag).ShType == "System Folder" && shChild.ShType.ToString() != "Local Disk")
                    continue;

This solves my problem but i don't know if this is the better way.. and does it have any bug..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.