I assume listLeft is your ListView. You need to add the following subtypes:
foreach (DirectoryInfo directory in directories) { ListViewItem lvi = new ListViewItem(); lvi.SubItems.Add("Directory " + directory.Name); listLeft.Items.Add(lvi); } foreach (FileInfo file in files) { ListViewItem lvi = new ListViewItem(); lvi.SubItems.Add(file.Name); listLeft.Items.Add(lvi); }
EDIT: Try the following:
private void button1_Click(object sender, EventArgs e) { try { listLeft.Columns.Add(new ColumnHeader()); FolderBrowserDialog folderPicker = new FolderBrowserDialog(); listLeft.View = View.Details; if (folderPicker.ShowDialog() == DialogResult.OK) { DirectoryInfo di = new DirectoryInfo(folderPicker.SelectedPath); FileInfo[] files = di.GetFiles(); DirectoryInfo[] directories = di.GetDirectories(); foreach (DirectoryInfo directory in directories) { listLeft.Items.Add("Directory " + directory.Name); } foreach (FileInfo file in files) { listLeft.Items.Add(file.Name); } } } catch (Exception ex) { MessageBox.Show("An error occurred: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
source share