Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. Select Multiple File in Single Open File Dialog Box

Select Multiple File in Single Open File Dialog Box

Scheduled Pinned Locked Moved Visual Basic
tutorialquestion
9 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TeiUKei
    wrote on last edited by
    #1

    I would like to create a open file dialog that can display multiple images in 1 single click. However, i only manage to select an image in 1 time. Could anyone please teach me how to select multiple image per open file dialog? Thanks so much! Dim OpenFile As OpenFileDialog = New OpenFileDialog Dim ImgName() As String Dim LoopCtrl As Integer OpenFile.Filter = "JPG Images|*.JPG|Bitmaps|*.BMP|GIF Images|*.GIF|All Images|*.BMP;*.GIF;*.JPG" OpenFile.FilterIndex = 10 OpenFile.Multiselect = True If OpenFile.ShowDialog = Windows.Forms.DialogResult.OK Then ImgName = OpenFile.FileNames For LoopCtrl = 0 To ImgName.Length - 1 objImage(LoopCtrl) = Image.FromFile(ImgName(LoopCtrl)) Next OriginalPic.Image = objImage(0) OriginalPic1.Image = objImage(1) End If This is how i write the code. Could anyone please kindly teach me how to select multiple image per open file dialog? Thanks so much!

    A 1 Reply Last reply
    0
    • T TeiUKei

      I would like to create a open file dialog that can display multiple images in 1 single click. However, i only manage to select an image in 1 time. Could anyone please teach me how to select multiple image per open file dialog? Thanks so much! Dim OpenFile As OpenFileDialog = New OpenFileDialog Dim ImgName() As String Dim LoopCtrl As Integer OpenFile.Filter = "JPG Images|*.JPG|Bitmaps|*.BMP|GIF Images|*.GIF|All Images|*.BMP;*.GIF;*.JPG" OpenFile.FilterIndex = 10 OpenFile.Multiselect = True If OpenFile.ShowDialog = Windows.Forms.DialogResult.OK Then ImgName = OpenFile.FileNames For LoopCtrl = 0 To ImgName.Length - 1 objImage(LoopCtrl) = Image.FromFile(ImgName(LoopCtrl)) Next OriginalPic.Image = objImage(0) OriginalPic1.Image = objImage(1) End If This is how i write the code. Could anyone please kindly teach me how to select multiple image per open file dialog? Thanks so much!

      A Offline
      A Offline
      Ajay k_Singh
      wrote on last edited by
      #2

      The code which you have written is correct. This will allow you to open a FileOpen dialog box. In this dialog box you may select multiple image files either by holding down control key, while selecting files or you may simply click on any empty area of dialog box and drag your mouse to select multiple files. In case if you are facing any problem in selecting multiple files, let us know. -Ajay.

      ------------------------- www.componentone.com -------------------------

      T 1 Reply Last reply
      0
      • A Ajay k_Singh

        The code which you have written is correct. This will allow you to open a FileOpen dialog box. In this dialog box you may select multiple image files either by holding down control key, while selecting files or you may simply click on any empty area of dialog box and drag your mouse to select multiple files. In case if you are facing any problem in selecting multiple files, let us know. -Ajay.

        ------------------------- www.componentone.com -------------------------

        T Offline
        T Offline
        TeiUKei
        wrote on last edited by
        #3

        First of all, thanks for reply. I was holding down the control key while selecting file, but it appeared that the file name changed and only 1 selected instead of both filenames appeared. Any solution to it? Thanks!

        A 1 Reply Last reply
        0
        • T TeiUKei

          First of all, thanks for reply. I was holding down the control key while selecting file, but it appeared that the file name changed and only 1 selected instead of both filenames appeared. Any solution to it? Thanks!

          A Offline
          A Offline
          Ajay k_Singh
          wrote on last edited by
          #4

          I used same code which has been given by and it is showing two different images on two different picture boxes. However I would like to inform you about one thing,when we select multiple files using Cntrl key, sequence of file names get changed. Therefore if you first click on ‘img1.jpg’ then img2.jpg’, it will become ‘img2.jpg’ ‘img1.jpg’. Therefore make sure that this fact is not creating any confusion. You may also get into debug mode and check value of ImgName to see how many file names are listed there. At my end I am getting correct number and list of files. -Ajay.

          ------------------------- www.componentone.com -------------------------

          T 1 Reply Last reply
          0
          • A Ajay k_Singh

            I used same code which has been given by and it is showing two different images on two different picture boxes. However I would like to inform you about one thing,when we select multiple files using Cntrl key, sequence of file names get changed. Therefore if you first click on ‘img1.jpg’ then img2.jpg’, it will become ‘img2.jpg’ ‘img1.jpg’. Therefore make sure that this fact is not creating any confusion. You may also get into debug mode and check value of ImgName to see how many file names are listed there. At my end I am getting correct number and list of files. -Ajay.

            ------------------------- www.componentone.com -------------------------

            T Offline
            T Offline
            TeiUKei
            wrote on last edited by
            #5

            Thanks..now i can select multiple file but it appeared some error lines. For the below coding For LoopCtrl = 0 To ImgName.Length objImage(LoopCtrl) = Image.FromFile(ImgName(LoopCtrl)) Next LoopCtrl It come out error "Object reference not set to an instance of an object". How i can solve it?

            A 1 Reply Last reply
            0
            • T TeiUKei

              Thanks..now i can select multiple file but it appeared some error lines. For the below coding For LoopCtrl = 0 To ImgName.Length objImage(LoopCtrl) = Image.FromFile(ImgName(LoopCtrl)) Next LoopCtrl It come out error "Object reference not set to an instance of an object". How i can solve it?

              A Offline
              A Offline
              Ajay k_Singh
              wrote on last edited by
              #6

              Make it - For LoopCtrl = 0 To ImgName.Length-1 objImage(LoopCtrl) = Image.FromFile(ImgName(LoopCtrl)) Next LoopCtrl ----------- If you are selecting two files, ImgName.Length will be 2, however index for two elements would be 0 and 1. Therefore we need to run loop from 0 to ImgName.Length-1. -Ajay.

              ------------------------- www.componentone.com -------------------------

              T 1 Reply Last reply
              0
              • A Ajay k_Singh

                Make it - For LoopCtrl = 0 To ImgName.Length-1 objImage(LoopCtrl) = Image.FromFile(ImgName(LoopCtrl)) Next LoopCtrl ----------- If you are selecting two files, ImgName.Length will be 2, however index for two elements would be 0 and 1. Therefore we need to run loop from 0 to ImgName.Length-1. -Ajay.

                ------------------------- www.componentone.com -------------------------

                T Offline
                T Offline
                TeiUKei
                wrote on last edited by
                #7

                Sorry for the trouble, it seems the same problem occur although i changed it as u have stated. Is there any other error? Dim OpenFile As OpenFileDialog = New OpenFileDialog Dim ImgName() As String Dim LoopCtrl As Integer OpenFile.Filter = "JPG Images|*.JPG|Bitmaps|*.BMP|GIF Images|*.GIF|All Images|*.BMP;*.GIF;*.JPG" OpenFile.FilterIndex = 10 OpenFile.Multiselect = True If OpenFile.ShowDialog = Windows.Forms.DialogResult.OK Then ImgName = OpenFile.FileNames For LoopCtrl = 0 To ImgName.Length - 1 objImage(LoopCtrl) = Image.FromFile(ImgName(LoopCtrl)) Next LoopCtrl OriginalPic.Image = objImage(0) OriginalPic1.Image = objImage(1) End If

                A 1 Reply Last reply
                0
                • T TeiUKei

                  Sorry for the trouble, it seems the same problem occur although i changed it as u have stated. Is there any other error? Dim OpenFile As OpenFileDialog = New OpenFileDialog Dim ImgName() As String Dim LoopCtrl As Integer OpenFile.Filter = "JPG Images|*.JPG|Bitmaps|*.BMP|GIF Images|*.GIF|All Images|*.BMP;*.GIF;*.JPG" OpenFile.FilterIndex = 10 OpenFile.Multiselect = True If OpenFile.ShowDialog = Windows.Forms.DialogResult.OK Then ImgName = OpenFile.FileNames For LoopCtrl = 0 To ImgName.Length - 1 objImage(LoopCtrl) = Image.FromFile(ImgName(LoopCtrl)) Next LoopCtrl OriginalPic.Image = objImage(0) OriginalPic1.Image = objImage(1) End If

                  A Offline
                  A Offline
                  Ajay k_Singh
                  wrote on last edited by
                  #8

                  What are OriginalPic and OriginalPic1? I also don’t see any declaration of objimage array in your code. Therefore I would like to how it is being declared and what is size of this array. In my code its declared as - Dim objimage(10) As Image -Ajay.

                  ------------------------- www.componentone.com -------------------------

                  T 1 Reply Last reply
                  0
                  • A Ajay k_Singh

                    What are OriginalPic and OriginalPic1? I also don’t see any declaration of objimage array in your code. Therefore I would like to how it is being declared and what is size of this array. In my code its declared as - Dim objimage(10) As Image -Ajay.

                    ------------------------- www.componentone.com -------------------------

                    T Offline
                    T Offline
                    TeiUKei
                    wrote on last edited by
                    #9

                    Finally get it right. What a mistake i make! Thanks for help!!

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups