Taking suggestion from this SO question, I'm populating a list view with paths array by converting it to NodeEntryCollection
by
NodeEntryCollection nodes = new NodeEntryCollection();
foreach (string line in lines)
{
nodes.AddEntry(line, 0);
}
Now on double click list view item I'm using this.
private void filesList_DoubleClick(object sender, EventArgs e)
{
if (filesList.SelectedItems.Count == 0) return;
if (filesList.SelectedItems[0].Tag.ToString() == "Folder")
{
string key = filesList.SelectedItems[0].Text;
filesList.Clear();
foreach (var item in nodes[key].Children) //Exception thrown here!
{
string fileName = Path.GetFileName(item.Key);
string extension = Path.GetExtension(fileName);
if (item.Value.Children.Count > 0)
{
ListViewItem itmNew = new ListViewItem(item.Key, 0);
itmNew.Tag = "Folder";
filesList.Items.Add(itmNew);
}
else
{
ListViewItem itmNew = new ListViewItem(item.Key, objIconListManager.AddFileIcon(fileName));
itmNew.Tag = "File";
filesList.Items.Add(itmNew);
}
}
}
}
It works fine on first directory and I see files from it but when I double click again on a subdirectory it throws:
[KeyNotFoundException was unhandled] The given key was not present in the dictionary.