Listbox'es and their items

Joined
May 10, 2011
Messages
5
Programming Experience
Beginner
Sorry if the title does not really explain the problem, not sure what to call it.


I have a listbox on my form, and a procedure that scans a certain directory for sub-directories, it then adds each subdirectory as a item in the listbox.


ex :


VB.NET:
Expand Collapse Copy
g:\movies\2010\Clash of The Titans
g:\movies\2010\Date Night
g:\movies\2010\Red Dawn
g:\movies\2010\Red Sonja
g:\movies\2011\Don't Be Afraid of the Dark
g:\movies\2011\Our Idiot Brother 
g:\movies\2011\Suing The Devil
g:\movies\2011\Shut Up Little Man


i would like to sort the listbox however by deleting/excluding the first part of the filename (g:\movies\2010) so that the listbox looks like this,


VB.NET:
Expand Collapse Copy
Clash of The Titans
Date Night
Red Dawn
Red Sonja
Don't Be Afraid of the Dark
Our Idiot Brother 
Suing The Devil
Shut Up Little Man


any ideas how i would go about doing this ?
 
Assuming that the original data is in a list named 'filePaths', this is one way:
Dim fileNames = filePaths.Select(Function(s) IO.Path.GetFileName(s)).OrderBy(Function(s) s).ToArray()

myListBox.AddRange(fileNames)
 
Back
Top