what i want to do is to search the items in the listview through textbox like when I type something all the items that has the same text that i type will appear or highlighted in the listview
I tried to use this
it has combobox to choose which columns to search toCode:Public Class StudentList Dim items As New List(Of ListViewItem) Private Sub GetStudents() Dim students As List(Of Students) students = StudentBAL.GetStudents() 'lvwStudents.Items.Clear() For Each student In students items.Add(New ListViewItem(student.ID.ToString)) With items.Last.SubItems .Add(student.LastName) .Add(student.FirstName) .Add(student.MiddleName) .Add(student.Address) .Add(student.Gender) .Add(student.Age) .Add(student.BirthDate) .Add(student.YearLevel) .Add(student.Course) .Add(student.TypeOfEnrollee) .Add(student.ContactNo) End With Next End Sub Private Sub StudentList_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load GetStudents() 'column header text should = column name for this to work ComboBox1.DataSource = (From ch In lvwStudents.Columns _ Let header = DirectCast(ch, ColumnHeader) _ Select header.Text).ToArray() End Sub Private Function isMatch(ByVal lvi As ListViewItem) As Boolean Return lvi.Text.StartsWith(txtSearch.Text) End Function Private Sub txtSearch_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtSearch.TextChanged Dim filteredItems() As ListViewItem = If(txtSearch.Text = "", items.ToArray, Array.FindAll(items.ToArray, Function(lvi) lvi.SubItems(ComboBox1.Text).Text.StartsWith(txtSearch.Text))) lvwStudents.Items.Clear() lvwStudents.Items.AddRange(filteredItems) End Sub
But when i run it the listview is empty . anyone can tell what is the problem or is their any better way ? thanks in advance![]()


Reply With Quote
Bookmarks