hi guys,

i have a problem regarding on how to view the image in the database when i select one information in my list view. and change it when i select another.

Public Sub studentList()

Me.ListView1.ListItems.clear

Set rs = New ADODB.Recordset

With rs
.Open "select * from tblStudentProfile", db, 3, 3

While Not .EOF

ListView1.ListItems.Add , , !StudentID
ListView1.ListItems(ListView1.ListItems.Count).SubItems(1) = !StudentLastName + ", " + !StudentFirstName + " " + !StudentMI
ListView1.ListItems(ListView1.ListItems.Count).SubItems(2) = !Age
ListView1.ListItems(ListView1.ListItems.Count).SubItems(3) = !Birthdate
ListView1.ListItems(ListView1.ListItems.Count).SubItems(4) = !HomeAddress
ListView1.ListItems(ListView1.ListItems.Count).SubItems(5) = !ContactNo
ListView1.ListItems(ListView1.ListItems.Count).SubItems(6) = !HSYear
ListView1.ListItems(ListView1.ListItems.Count).SubItems(7) = !HSSection
txtIDpicture.Text = Me.ListView1.SelectedItem.Text
If txtIDpicture.Text = Me.ListView1.SelectedItem.Text Then

Me.CommonDialog1.FileName = !ProfilePicture
Picture1.Picture = LoadPicture(CommonDialog1.FileName)

End If


.MoveNext
Wend

End With
lblTotal.Caption = ListView1.ListItems.Count

Set rs = Nothing


End Sub

Use the ItemClick event

Please, use code tags when posting your code: "code=vb6" "/code" but use brackets [] instead of quotation marks.

Click on the Code Tag Icon next to quote tag in the editor. It should paste the appropriate code tags into the editor automatically.

Private Sub ListView1_ItemClick(ByVal Item As ComctlLib.ListItem)
    Dim strItem As String
    strItem = Item
    Debug.Print Item
    ' Use strItem as the basis for SQL query
    ' Write the code
End Sub

ah only need to copy and paste my code in that item click event? OK.
Sorry for the post.. i'm new here

thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.