Problem displaying images in table

FDisk

Newcomer
Joined
Apr 17, 2004
Messages
9
Hey everyone, I'm sort of new here, I've been reading the boards for a while but this is the first time I post.

I'm taking a VB class and I want to do an extra credit assignment that consists of creating a web application.

The problem I'm having is that the table only shows the image at the last cell. It populates the tool tips fine, but only shows the cell and image for the last one. The program is supposed to get the image and tooltip from the database, there's an extra field in the database called "SignID" which is numbers 1-15 (There's 15 images in total, the table is 5 columns by 3 rows) but I don't think I need to use it since I'm using intIndex to place the images in the cells.

Anyway, here's my code, thanks in advance for any help/advice:

Code:
 Dim imgSign As Image = New Image
        Dim intCount As Integer = 0
        Dim intIndex As Integer = 0

        Me.objOleDbConnection.Open()
        Dim objReader As OleDbDataReader

        objReader = Me.objOleDbSelectSignInformation.ExecuteReader()

        Do While intCount < 5
            objReader.Read()
            imgSign.ImageUrl = "SignImages/" & objReader("sign").ToString
            tblRoadSigns.Rows(0).Cells(intIndex).Controls.Add(imgSign)
            tblRoadSigns.Rows(0).Cells(intIndex).ToolTip = objReader("name").ToString
            intCount += 1
            intIndex += 1
        Loop
        intIndex = 0
        Do While intCount >= 5 And intCount < 10
            objReader.Read()
            imgSign.ImageUrl = "SignImages/" & objReader("sign").ToString
            tblRoadSigns.Rows(1).Cells(intIndex).Controls.Add(imgSign)
            tblRoadSigns.Rows(1).Cells(intIndex).ToolTip = objReader("name").ToString
            intCount += 1
            intIndex += 1
        Loop
        intIndex = 0
        Do While intCount >= 10 And intCount < 15
            objReader.Read()
            imgSign.ImageUrl = "SignImages/" & objReader("sign").ToString
            tblRoadSigns.Rows(2).Cells(intIndex).Controls.Add(imgSign)
            tblRoadSigns.Rows(2).Cells(intIndex).ToolTip = objReader("name").ToString
            intCount += 1
            intIndex += 1
        Loop

        objReader.Close()

        Me.objOleDbConnection.Close()
 
I think the problems is this line:

Dim imgSign As Image = New Image

Remember that by saying New Image you are creating 1 new image. Therefore you need to say imgSign = new Image inside your loops before you do the controls.add(imgSign).

Thats the reason you are only getting the last image because you overwrite the variable everytime, therefore the imgSign object is only ever the last one.

Hope that helps!!
 
I cannot thank you enough

tonyf said:
I think the problems is this line:

Dim imgSign As Image = New Image

Remember that by saying New Image you are creating 1 new image. Therefore you need to say imgSign = new Image inside your loops before you do the controls.add(imgSign).

Thats the reason you are only getting the last image because you overwrite the variable everytime, therefore the imgSign object is only ever the last one.

Hope that helps!!

Genius thy name is Tony. It works perfectly now. You have no idea how much time I spent going over this thing until I gave up and decided to turn to the pros for help. Thank you so much for your help!

P.S. This forum is amazing
 
Back
Top