Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Showing different images in one imagebox control in vb6 1

Status
Not open for further replies.

namax

Technical User
May 22, 2011
19
PG
Dear All,

I have written a database for student profiles and encountered a problem when using mshflexgrid control. I have successfully populated the mshflexgrid control with records from my access database, put one imagebox in the same form where the mshflexgrid is.

What I want is when the user clicks an ID of a student in the grid control the image should change and show that particular student's photo. I tried putting in some code and it's loading the images but not able to show images when I randomly click an ID from the grid. What it's doing is that when I click the first record from the grid, I must click each record in order to show each images perfectly but will not show right image if I skip a record and click anywhere. I have to go like, click first record, second, third and so forth till I reach the end. And when I reach the end it won't work if I go back and click on the first record, it shows only the last image of the last record. I have included 'rs.MoveNext' in my code because if I don't then the images don't change when I click through the IDs in the grid but only the image of the first student in the database shows. This is my code:

Private Sub MSHflexGrid1_click()
On Error GoTo BrowseError_Handling
Text2 = MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, MSHFlexGrid1.Col)

If Text2.Text = rs!id Then
Image1.Picture = LoadPicture(rs!id_photo)
rs.MoveNext
End If

Browse_Error:
Exit Sub

BrowseError_Handling:
If Err = 53 Then
MsgBox "Image doesn't exist!", vbInformation, "Browse Error"
Resume Browse_Error
End If
End Sub

Note: 'id' is my students' ID field,'id_photo' is the field that stores the path to the images of the students and 'rs' is my recordset.

I assume the best way is to write a loop but frankly I am not well versed in this part of coding.

Could you please assist me in any tips or ideas that I can follow to solve this problem which has taken me almost a month now.

Thank you in advance for your time and consideration.

regards,

YU
 
You don't need to pull data from your recordset. Instead, you can use the FlexGrid control to query the data (image path) directly.
Something like this...

[tt]Image1.Picture = LoadPicture(MSHFlexGrid1.TextMatrix(MSHFlexGrid1.Row, N))[/tt]

Where N is the column number where 'id_photo' field is displayed in the FlexGrid.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top