StealthRT
StealthRT

Reputation: 10552

VB.net Listview select

I am having problems with highlighting the found listview item using the code below:

If lstMaster.View = View.Details AndAlso lstMaster.Items.Count > 0 Then
    Dim lvi As ListViewItem = lstMaster.FindItemWithText(txtSearchSR.Text, True, 0)

    If lvi IsNot Nothing Then
        MsgBox("found")
        lvi.ListView.Items(0).Selected = True  'Does not seem to work...
    End If

End If

How do i highliht the found column?

David

Upvotes: 1

Views: 8935

Answers (3)

StealthRT
StealthRT

Reputation: 10552

Got it! :o)

lstMaster.Items(lvi.Index).Selected = True
lstMaster.Select()
lstMaster.SelectedItems.Item(0).EnsureVisible()

Upvotes: 1

Bala R
Bala R

Reputation: 109027

You need

lvi.Selected = True

From your snippet,

lvi.ListView.Items(0) will always return the first ListViewItem in the listview.

Upvotes: 1

Wicked Coder
Wicked Coder

Reputation: 1118

Try setting Subitems

lvi.Items[0].UseItemStyleForSubItems = false
lvi.Items[0].SubItems[0].BackColor = Color.Black     
lvi.Items[0].SubItems[0].ForeColor = Color.White

if that doesn't work try

lvi.UseItemStyleForSubItems = false
lvi.SubItems.Add(new ListViewItem.ListViewSubItem(lvi,"subitem", Color.Black, Color.White, lvi.Font )) 

Upvotes: 1

Related Questions