Problem with picture hotspot

claire_bicknell

Well-known member
Joined
Dec 10, 2008
Messages
49
Programming Experience
Beginner
I have created a hotspot on a picture that when clicked reveals a second picture.

For example: Debenhams has a picture 1 that when clicked shows picture 2.

The problem I have is when i have a second shop for example John Lewis, i click picture number 1 and it shows me Debenhams picture2 instead of its own picture 2.

Why could this be?

This is the fragment of code:

HTML:
Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
        Dim strLoad_File As String
        Dim intRow As Integer

        For Each place As String In places.Keys
            If places(place).Contains(e.Location) Then

                strLoad_File = myDataTable.Rows(intRow).Item("Picture2")
                PictureBox1.Load(IO.Path.Combine(Application.StartupPath, strLoad_File))

                Exit For
            End If
        Next
    End Sub

Any help much appreciated
 
What index are you using to get the row containing the image?
VB.NET:
strLoad_File = myDataTable.Rows([B][U]intRow[/U][/B]).Item("Picture2")
Do you ever assign a value to intRow? No you don't, so it will always be 0 and you'll always get the image from the first row.
 
So what do I need to change to get this working? I am a little confused.

I understand that I am currently only returning the picture assigned in row1 of my database but how can I amend this so it returns different pictures?
 
You have to use the index of row that contains the image path you need to retrieve. I can't tell you how to do that from the code you've posted because I don't know how that index relates to anything else.
 
Attached is a screenshot of my shop database.

By index, do you mean the number of the column of Picture2? In this case no.6?

Thanks again :)
 

Attachments

  • shop.jpg
    shop.jpg
    118.5 KB · Views: 31
Last edited by a moderator:
If you have N rows then they are at indexes 0 to (N - 1). You're using index 0 no matter what, so you're always going to get the picture for the first row. If you want to get a different image file name then you have to use a different index.

Presumably each "place" corresponds to a different row so you need to use the place to determine the index of that row so you can then get the image file name from the row at that index.
 
Back
Top