Select a ListViewItem from outside

  • Thread starter Thread starter Joerg Trumpfheller
  • Start date Start date
J

Joerg Trumpfheller

Hey folks,

I have a problem with selecting an item in a listview control from outside.

Listview items are binded with unique ids.
I got now an id from another control and want to select the specific
listview-item. Is there a chance I haven't seen jet?

Thanks for you help
Joerg
 
Maybe I have to explain it more detailed:

I have a windows form looks like the windows explorer with an treeview,
listview and an imageviewer containing layers where markers for the filterd
listview items are painted. With the key of the selected listview item I can
highlight the marker of the imageviewer control. With the key of the
selected marker in the imageviewer control I want to select the specific
listview item. How does this work?
Almost all properties of the listview control are read only.
Does this work with getitemat(x,y) and how?

Would be so awesome if someone knows a way.

Joerg
 
For those who are interrested - here is a solution

Private Sub ImageViewer_SelectHandler(Byval SearchID as long) Handles
RaiseEventfrom.MarkerSelected

Try

Dim selItems As New ListView.ListViewItemCollection(ListView1)

Dim lviProps As ListViewItemProps

Dim i As ListViewItem

For Each i In selItems

Dim ind As Integer = i.Index

' Parse the Tag

lviProps = CType(i.Tag, ListViewItemProps)

If (CLng(lviProps.ItemKey) = SearchID) Then

Debug.WriteLine("Found: " & CLng(lviProps.ItemKey) & " - " & SearchID)

selItems(ind).Selected = True

Else

selItems(ind).Selected = False

End If

Debug.WriteLine(CLng(lviProps.ItemKey) & " - " & SearchID)

Next i

Catch ex As Exception

Throw New Exception(Me.ToString & ".ImageViewer_SelectHandler: " &
ex.ToString & vbCrLf)

End Try

end sub



Public Structure ListViewItemProps

Dim ItemKey As Object

....

End Structure



Joerg
 
Back
Top