image List problems, using list box [resolved]
Right i have two controls, a list box and an image box. The list box is populated with random values, of which coraspond (spelling???) with the images in the image list, so when i click on the list box i want the correct image to be displayed.
How would i do this?
Thank you in advance
ILMV
Re: image List problems, using list box
How do they correspond (it takes a Swede to learn an Englishman how to spell in English :)) to each other?
Re: image List problems, using list box
In the click event get the ListBox.Text and based on the item selected, get the image like this probably :
VB Code:
ImageList1.ListImages.Item(CInt(ListBox.Text))
Joacim, is Swede correct? It looks funny :)
Re: image List problems, using list box
Well the values in the list box will be for example "Spade12", or "Club1", you can see the idea, well i have named each 'corresponding' card the same, for example "Spade12" etc.
Re: image List problems, using list box
Quote:
Originally Posted by I_Love_My_Vans
Right i have two controls, a list box and an image box. The list box is populated with random values, of which coraspond (spelling???) with the images in the image list, so when i click on the list box i want the correct image to be displayed.
How would i do this?
Thank you in advance
ILMV
First add a list box, an Image Control and a ImageList to a form. Use the default names for each control. Then add a few images to the ImageList and then paste this code:
VB Code:
Option Explicit
Private Sub Form_Load()
Dim a As Long
With Me.List1
For a = 1 To Me.ImageList1.ListImages.Count
.AddItem "Picture " & a
Next a
End With
End Sub
Private Sub List1_Click()
Dim indx As Long
indx = Me.List1.ListIndex + 1
Me.Image1.Picture = Me.ImageList1.ListImages(indx).Picture
End Sub
Re: image List problems, using list box
The easiest way would be if you have added the ListItems using "Spade12" or "Club1" as the Key value. You could then use code simular to this:
VB Code:
Private Sub List1_Click()
Set ListView1.SelectedItem = ListView1.ListItems(List1.Text)
End Sub
Re: image List problems, using list box
Re: image List problems, using list box
Quote:
Originally Posted by I_Love_My_Vans
Well the values in the list box will be for example "Spade12", or "Club1", you can see the idea, well i have named each 'corresponding' card the same, for example "Spade12" etc.
Ok, change the List_Click Event in my code to:
VB Code:
Private Sub List1_Click()
Me.Image1.Picture = Me.ImageList1.ListImages(Me.List1.Text).Picture
End Sub