Hello and good day...
I need to create a picturebox that allows different pics to show when The user clicks an item in a combo box. in vb.net.....
Any help on how to go about it is welcomed
Printable View
Hello and good day...
I need to create a picturebox that allows different pics to show when The user clicks an item in a combo box. in vb.net.....
Any help on how to go about it is welcomed
Hello, i have done a sample code for you.
Instructions
1. Pull a ComboBox (named ComboBox1) and a PictureBox (named PictureBox1) to the form
2. Copy the following code to the editor
3. Change the directory path that contains the images.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dirInfo As New System.IO.DirectoryInfo("C:\Users\Public\Pictures\Sample Pictures")
ComboBox1.DataSource = dirInfo.GetFiles("*.jpg")
ComboBox1.DisplayMember = "Name"
ComboBox1.Refresh()
UpdatePicture()
End Sub
Private Sub UpdatePicture()
If ComboBox1.SelectedIndex < 0 Then Exit Sub
Dim f As System.IO.FileInfo
f = CType(ComboBox1.SelectedItem, System.IO.FileInfo)
PictureBox1.Image = System.Drawing.Image.FromFile(f.FullName)
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
UpdatePicture()
End Sub
Thanks I got that working .... I already have a list of items in my combobox and I want Images to occur in the picture box area once its click........
Have you copy this sub to the code editor
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Having this event, the picture box should load the picture when the combox item selection is changed.
By the way, what are your images extension?
Thanks I have it solved already