Results 1 to 8 of 8

Thread: image List problems, using list box [resolved]

  1. #1

    Thread Starter
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    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
    Last edited by I_Love_My_Vans; Jun 11th, 2005 at 02:48 PM.

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    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?

  3. #3
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    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:
    1. ImageList1.ListImages.Item(CInt(ListBox.Text))

    Joacim, is Swede correct? It looks funny


    Has someone helped you? Then you can Rate their helpful post.

  4. #4

    Thread Starter
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    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.

  5. #5
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    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:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4. Dim a As Long
    5.  
    6.     With Me.List1
    7.         For a = 1 To Me.ImageList1.ListImages.Count
    8.             .AddItem "Picture " & a
    9.         Next a
    10.   End With
    11.  
    12. End Sub
    13.  
    14. Private Sub List1_Click()
    15. Dim indx As Long
    16.     indx = Me.List1.ListIndex + 1
    17.     Me.Image1.Picture = Me.ImageList1.ListImages(indx).Picture
    18. End Sub
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


  6. #6
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    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:
    1. Private Sub List1_Click()
    2.     Set ListView1.SelectedItem = ListView1.ListItems(List1.Text)
    3. End Sub

  7. #7

    Thread Starter
    Frenzied Member I_Love_My_Vans's Avatar
    Join Date
    Jan 2005
    Location
    In the PHP compiler
    Posts
    1,275

    Re: image List problems, using list box

    Got it working, cheers

  8. #8
    Giants World Champs!!!! Mark Gambo's Avatar
    Join Date
    Sep 2003
    Location
    Colorado
    Posts
    2,965

    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:
    1. Private Sub List1_Click()
    2.     Me.Image1.Picture = Me.ImageList1.ListImages(Me.List1.Text).Picture
    3. End Sub
    Regards,

    Mark

    Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width