Read icon from a ListView?

Mugsy's RapSheet 196 Reputation points
2025-04-20T00:07:14.73+00:00

I have a ListView that displays a checkbox, icon, and name of every png in a user-selected folder.

On the form is an Imagebox named "picPreview". I want to display an enlarged preview of the icon on the form when I hover over each item in the listview (the below code isn't valid code. It's simply what I'm seeking to do.)

Private Sub lsvCollection_MouseMove(sender As Object, e As MouseEventArgs) Handles lsvCollection.MouseMove

' Display enlarged preview of icon on Hover.

Dim currentItem As ListViewItem = lsvCollection.GetItemAt(e.X, e.Y)

For Each item As ListViewItem In lsvCollection.Items

If currentItem IsNot Nothing Then

BOGUS CODE> **picPreview.Image = lsvCollection.Items(currentItem.Index).Image**

End If

Next

End Sub

If I must, I can determine the image filename from the index and load it straight off the HDD, but that's slow & inefficient. Is there any way to obtain the currently focused icon from the ListView and simply re-display it?

TIA

ADDENDUM: I can obtain the image from the ImageList that was used to populate the ListView, but if the ListView is then sorted, the icons no longer match. :(

"Working" code: picPreview.Image = ImageList2.Images(currentItem.Index)

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,827 questions
0 comments No comments
{count} votes

Accepted answer
  1. RLWA32 48,151 Reputation points
    2025-04-20T15:41:45.53+00:00

    Handle the ListView.ItemMouseHover Event. The event will give you the listview item that the mouse is hovering over and you can use the imagindex from that item.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.