Groups | Blog | Home
all groups > vb.net controls > june 2005 >

vb.net controls : ListView Control Problem


Ellis Yu
6/3/2005 4:51:49 PM
Dear All,

I'm trying to write a searchable list view that it will scroll to
the item which is like the user inputed in a textbox. The codes as below

Private Sub btnFind_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnFind.Click
Dim itm As ListViewItem
For Each itm In lvwSearchResult.Items
If itm.SubItems(1).Text.ToUpper.IndexOf(txtName.Text.ToUpper) >
0 Then
itm.EnsureVisible()
itm.Selected = True
Return
End If
Next
End Sub

In the above, I had set the itm.selected to true, but the item didn't
highlighted. Is there any wrong on my codes?

Best Rdgs
Ellis

Ken Tucker [MVP]
6/3/2005 8:41:22 PM
Hi,

Make sure the listview's hideselection property is set to false.
Otherwise the listview will only show highlighted items when it has focus.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformslistviewclasshideselectiontopic.asp

Ken
-----------------
[quoted text, click to view]
Dear All,

I'm trying to write a searchable list view that it will scroll to
the item which is like the user inputed in a textbox. The codes as below

Private Sub btnFind_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnFind.Click
Dim itm As ListViewItem
For Each itm In lvwSearchResult.Items
If itm.SubItems(1).Text.ToUpper.IndexOf(txtName.Text.ToUpper) >
0 Then
itm.EnsureVisible()
itm.Selected = True
Return
End If
Next
End Sub

In the above, I had set the itm.selected to true, but the item didn't
highlighted. Is there any wrong on my codes?

Best Rdgs
Ellis


Ellis Yu
6/6/2005 12:00:00 AM
Many Thanks !!!

[quoted text, click to view]
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemwindowsformslistviewclasshideselectiontopic.asp
[quoted text, click to view]

AddThis Social Bookmark Button