I'm trying to sort images before assigning them to an ImageList object.
Using a "For... Each" loop, I can assign images one at a time as they are read directly from the computer.
The problem is, this method reads the files alphabetically, so it reads "image09.png", "image10.png", "image100.png", "image101.png", "image102.png", etc before "image11.png" (physically renumbering the users files is not an option.)
My "solution" was to read the images into an array of type Image, inserting images into the array in order, then assign that array to my "ImageList" object.
This results in an assignment error, and I have no idea why.
Is there any other way to assign images to an ImageList control other than directly from disk?
TIA
Using a "For... Each" loop, I can assign images one at a time as they are read directly from the computer.
The problem is, this method reads the files alphabetically, so it reads "image09.png", "image10.png", "image100.png", "image101.png", "image102.png", etc before "image11.png" (physically renumbering the users files is not an option.)
My "solution" was to read the images into an array of type Image, inserting images into the array in order, then assign that array to my "ImageList" object.
This results in an assignment error, and I have no idea why.
Can't assign image array to an ImageList (error on line 11):
Dim imgImageArray(200) As Image
...
For Each ClosetFile As String In IO.Directory.GetFiles(strClosetPath, strCategory & "*.png", SortOrder.Ascending)
...
Dim img = Image.FromFile(ClosetFile)
imgImageArray(intPosition) = img ' "intPosition" parsed from filename.
...
Next ' ending For/Each loop.
For intCnt = 1 To intTotalNumberOfFiles ' Load image array with sorted list.
ImageList2.Images.Add(imgImageArray(intCnt))
' also tried: ".AddRange" w/o the loop.
Next
Is there any other way to assign images to an ImageList control other than directly from disk?
TIA
Last edited: