Click here to Skip to main content
15,892,965 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to add listBox dirve & subdirectories data
Posted
Updated 5-Oct-11 2:12am
v2
Comments
Sergey Alexandrovich Kryukov 5-Oct-11 14:18pm    
Why?
Do you need only one level of sub-directories? Why?
--SA

Can't you just use FolderBrowserDialog?

http://msdn.microsoft.com/en-us/library/system.windows.forms.folderbrowserdialog.aspx[^]

C#
string folderPath = "";
FolderBrowserDialog folderBrowserDialog1 = new FolderBrowserDialog();
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
    folderPath = folderBrowserDialog1.SelectedPath;
}



Cheers!
 
Share this answer
 
Most likely, ListBox is not adequate control, as the file systems is hierarchical. (Well, it's more complex graph than a tree as there are links and symlinks (reparse points in Windows terminology), but we can forget about it.)

The more adequate control for what you want to show is TreeView. There is only one problem, but a pretty difficult one: the directory levels should be added dynamically and removed as the user expands and collapses nodes, otherwise performance would be unacceptable.

It looks like the authors of these article do it right:
Filesystem TreeView[^],
http://www.codingforums.com/showthread.php?t=98085[^].

Even if you insist on ListBox, reading of these articles will give you all information you may possibly need to accomplish this task.

—SA
 
Share this answer
 
v2
there is a control that do this
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900