CheckedListBox
-
I tried to list drives available in a system in checkedlistbox.When i click on the C:\ i want to list its files in a listview.I tried with the following but it does not work.Can you give me an alternative.<pre> int p=checkedListBox1.SelectedIndex; if(p==1) { try { reader = new XmlTextReader("path.xml"); while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Text: //Display the text in each element. // Console.WriteLine(reader.Value); String s1; s1 = reader.Value; String ss; ss = checkedListBox1.CheckedItems.ToString(); String sss = ss + s1; object o3 = (object)sss; DirectoryInfo dire = new DirectoryInfo(sss); //DirectoryInfo[] dirs = dire.GetDirectories(); if (dire.Exists) { String[] folder; folder = Directory.GetDirectories(sss); foreach (string foldername in folder) { DirectoryInfo di = new DirectoryInfo(foldername); if (di.Exists) { String[] files; files = Directory.GetFiles(foldername, "*.exe*"); //FileInfo[] fi = dire.GetFiles(); foreach (String filename in files) { lvi = new ListViewItem(); lvi.Text = filename; listView1.Items.Add(lvi); } this.Controls.Add(listView1); } } } break; }
-
I tried to list drives available in a system in checkedlistbox.When i click on the C:\ i want to list its files in a listview.I tried with the following but it does not work.Can you give me an alternative.<pre> int p=checkedListBox1.SelectedIndex; if(p==1) { try { reader = new XmlTextReader("path.xml"); while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Text: //Display the text in each element. // Console.WriteLine(reader.Value); String s1; s1 = reader.Value; String ss; ss = checkedListBox1.CheckedItems.ToString(); String sss = ss + s1; object o3 = (object)sss; DirectoryInfo dire = new DirectoryInfo(sss); //DirectoryInfo[] dirs = dire.GetDirectories(); if (dire.Exists) { String[] folder; folder = Directory.GetDirectories(sss); foreach (string foldername in folder) { DirectoryInfo di = new DirectoryInfo(foldername); if (di.Exists) { String[] files; files = Directory.GetFiles(foldername, "*.exe*"); //FileInfo[] fi = dire.GetFiles(); foreach (String filename in files) { lvi = new ListViewItem(); lvi.Text = filename; listView1.Items.Add(lvi); } this.Controls.Add(listView1); } } } break; }
Two things. First you forgot to include the closing </pre> tag. Secondly, what you are trying to do is sort-of like Windows Explorer so a quick google on 'explorer c#' reveals My Explorer In C#[^], as the first hit. If that doesn't give you any ideas, google for yourself and have a look at some of the other hits.
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.”