Getting listbox files to show as image

Wicked_

Board Regular
Joined
Jun 5, 2018
Messages
81
Hi.

I have a Listbox and a Image (imagebox) in my userform.
I then have a code in the listbox that gather images from a folder to the listbox.
Example, if i have 3 images called "image1, image2, image3" (in a folder), they pop-up in the listbox correctly.

But now, i would like to show those pictures in the imagebox which i have next to the listbox. So like, if i press the Image1 file from the listbox, i would like it to show the image on the imagebox.

I have searched for this alot, but havent found a relevant code that fulfills what i need.

Is there anyone that could help me with this? :)

Thanks in advance!
 
You said:
I then have a code in the listbox that gather images from a folder to the listbox.

Show us this code please:
 
Upvote 0
Hi. here is the code i use for that:

Private Sub UserForm_Initialize()
Filename = Dir("O:\Mask\Measure\1156" & "\*.jpg", vbNormal)




Do While Len(Filename) > 0


UserForm4.ListBox1.AddItem Filename




Filename = Dir()
Loop




End Sub

With this code, all the images i got on that folder shows correctly in the ListBox, but im stuck how to show the actual image on the image"box" when i click on a image from the listbox :)
 
Upvote 0
From my understanding you cannot add images to a UserForm Listbox

Maybe your referring to a Listview control that you have named ListBox1.

Or am I wrong?
 
Upvote 0
Hi again.

"From my understanding you cannot add images to a UserForm Listbox"

Hmm, i'll try to show a picture of what i mean (Even tho you might be thinking of what i am thinking)

https://imgur.com/a/4wZhwZ7

(there i would click the "Test.jpg" and on the right (in a "image" box) the image would show.)

Not sure about the Listview (trying to learn the best i can)


 
Upvote 0
I see now. You do not have a image in your listbox. You have a image name in your listbox.
 
Upvote 0
Precisely. The images itself is stored in the folder. So everytime i add a new image there, the filename shows up on the listbox, but cant get it to show the actual image in the imagebox when i click the imagename.
 
Upvote 0
Interesting question.
So all that shows up in your list box is:
Test.Jpg

So I would think the script would also need the path to the image.

This is beyond my knowledgebase.
I will continue to monitor this thread to see what I can learn.
 
Upvote 0
Assuming your Image control is named Image1, you could use the change event of the listbox to populate it using Loadpicture

Code:
Me.Image1.Picture = Loadpicture("O:\Mask\Measure\1156\" & Listbox1.Value)
 
Upvote 0
Assuming your Image control is named Image1, you could use the change event of the listbox to populate it using Loadpicture

Code:
Me.Image1.Picture = Loadpicture("O:\Mask\Measure\1156\" & Listbox1.Value)


Worked like a charm!
Thank you alot!
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top