[go: up one dir, main page]

0% found this document useful (0 votes)
19 views1 page

Public Form1

The document contains a C# code snippet for a Windows Forms application that initializes a form with a tree view and list view. It loads available drives and their directories into the tree view, and displays files in the list view when a directory is clicked. The form also includes a label to show the current path but lacks functionality for the button click event.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views1 page

Public Form1

The document contains a C# code snippet for a Windows Forms application that initializes a form with a tree view and list view. It loads available drives and their directories into the tree view, and displays files in the list view when a directory is clicked. The form also includes a label to show the current path but lacks functionality for the button click event.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

{

public Form1()
{
InitializeComponent();
}

private void listView1_SelectedIndexChanged(object sender, EventArgs e)


{

private void Form1_Load(object sender, EventArgs e)


{
this.treeView1.Nodes.Clear();
this.listView1.Items.Clear();
this.label1.Text = "Path: ";
LoadDrives();
}
private void LoadDrives()
{
DriveInfo[] drives = DriveInfo.GetDrives();
foreach (var drive in drives)
{
if (drive.IsReady)
{
TreeNode trenode = this.treeView1.Nodes.Add(drive.Name);

DirectoryInfo[] dirs = new


DirectoryInfo(drive.Name).GetDirectories();
foreach (var dir in dirs)
{
trenode.Nodes.Add(drive.Name);
}
}
}
}

private void treeView1_NodeMouseClick(object sender, TreeViewEventArgs e)


{
string path = e.Node.FullPath + @"..\";
this.label1.Text = string.Format("Path: {0}", path);
FileInfo[] files = new DirectoryInfo(path).GetFiles();
foreach (var file in files)
{
ListViewItem item = this.listView1.Items.Add(file.Name);
}

private void button1_Click(object sender, EventArgs e)


{

}
}
} 0976624134

You might also like