Question : VB.NET: how to highlight listview item and place on TOP

Hi X-perts,

It is a simple question, but I cannot find a quick answer: how to highlight a certain item of ListView and place on TOP? The problem is that the found item is sometimes on the 3rd or 4th line (not necessarily a top line)

Pls, advise,

thanks
Code Snippet:
1:
2:
3:
4:
5:
Dim foundItem As ListViewItem = .ListView2.FindItemWithText(.TextBoxMSTSearch.Text, False, 0, True)
                If Not (foundItem Is Nothing) Then
                    .ListView2.TopItem = foundItem
                    foundItem.Selected = True
                End If

Answer : VB.NET: how to highlight listview item and place on TOP

Use your old code: //slight modification
Dim foundItem As ListViewItem = .ListView2.FindItemWithText.TextBoxMSTSearch.Text, False, 0, True)
                If Not (foundItem Is Nothing) Then
                    foundItem.Selected = True
                    .ListView2.TopItem = foundItem
                End If
 and make sure ListView2.EnsureVisible and Scrollable are true
Note: Be aware that you might have problems using this code if this item is in the last page. From MSDN: "If you set the TopItem property to an item in the last page of the ListView, the item will automatically be scrolled into view; however, TopItem will be set to the actual top item of the last page.
"

Random Solutions  
 
programming4us programming4us