none
How to sort images RRS feed

  • Question

  • I want to have like three Picture Boxes and a Button. When the button is pressed it opens an OpenFileDialog.

    I have all of this but what I need is that when these images are imported by the user I want them to sort themselves alphabetically in the Picture Boxes.

    Example Pictures Apple, Banana, Cactus

    Picture Box 1 = Apple

    Picture Box 2 = Banana

    Picture Box 3 = Cactus

    These name would be their SafeFileNames.

    Any help is appreciated thanks in advance.

    Sunday, April 15, 2018 6:51 PM

All replies

  • You can write your class MImage. There will be string SaveFileName property and Image property.

    Then you will have List<MImage> mImages and when images from dialog are selected you fill list by concrete instances of MImages. 

    Then you can sort it by LINQ - 

    mImages = mImages.OrderBy(k=>k.SaveFileName).ToList();

    PictureBox1.Image = mImages[0].Image;

    ...

    • Proposed as answer by daktmacfan Monday, April 16, 2018 1:58 AM
    Sunday, April 15, 2018 9:03 PM
  • As in your other thread on similar if not same topic you could use a List(Of String) to store the paths for the files and sort the list so it is containing the paths alphabetically if all files are in the same path and same image type (i.e. Png or Jpg, etc).

    You could add all the PictureBox's in order to a List(Of PictureBox) and if both lists are the same length it should be simple to provide each PictureBox with Image From File from the List(Of String) in a loop.


    La vida loca

    Sunday, April 15, 2018 9:42 PM