Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Remove elements of a List<DirectoryInfo>

Status
Not open for further replies.

ralphtrent

Programmer
Jun 2, 2003
958
US
Hello
I have an app that list folders matching some naming critera. I saved the folder paths to a List<System.IO.DirectoryInfo> object. I allow the user to delete folders of their choosing's. When they do, I need to remove the folder from the list. Obviously its not working.

Here is my code to remove
Code:
System.Collections.Generic.List<System.IO.DirectoryInfo> 
pFolders.Add(new System.IO.DirectoryInfo(dgrv.Cells["FolderPath"].Value.ToString()));
[green]// The results are displayed in a DataGridView with checkboxes for each row.  If the row is check, i add it to pFolder
[/green]
pFolders = new List<System.IO.DirectoryInfo>();

foreach (System.IO.DirectoryInfo dir in pFolders)
{
	if (!dir.Exists)
	{
[green]//gglSelectedFolderList is myList<>
[/green]gglSelectedFolderList.Remove(gglSelectedFolderList.Find(removeUncheckedFolder));
	}
}

[green]// Here is my predicate [/green]
private bool removeUncheckedFolder(System.IO.DirectoryInfo dir)
{
        if (!dir.Exists)
	{ 
		return true; 
	}
	else
	{
		return false;
	}
}

It looks like the two list are not sorted in the same order and I think that is whats screwing me up when I go to remove.

Any idea on what I am doing wrong?

Thanks,
RalphTrent
 
This is fixed. My predicate search was fine. I forgot I had to List<System.IO.DirectoryInfo>. I was trying to remove from the wrong one. DOH!. Sorry, got Froyo for Droid on the mind today and its a bit nutty.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top