Below is the code I am working with. My accounts are stored in a Dictionary(Of String, Integer) so that I can easily associate a value with them. My listview is working great after I converted it to virtualmode but I lost the functionality to search simply by typing in the listview which is what I would like to get back. Without it this makes the whole feature practically useless unless I can search by name. I have searched and implemented multiple examples and I cannot get anything to work. What am I doing wrong? How should it look?
This populates my listview.
Private Sub lstAccounts_RetrieveVirtualItem(sender As Object, e As RetrieveVirtualItemEventArgs) Handles lstAccounts.RetrieveVirtualItem
lstAccounts.VirtualListSize = MainForm.accounts.Count 'Update after a dictionary edit.
Dim i As New ListViewItem(MainForm.accounts.Keys(e.ItemIndex))
If MainForm.accounts.ContainsKey(MainForm.accounts.Keys(e.ItemIndex).ToString) Then
i.SubItems.Add(MainForm.accounts.Item(i.Text))
End If
e.Item = i
End Sub
This is from MSDN. Supposedly required for searching, only example I could find..
Private Sub lstAccounts_SearchForVirtualItem(sender As Object, e As SearchForVirtualItemEventArgs) Handles lstAccounts.SearchForVirtualItem
Dim x As Double = 0
If [Double].TryParse(e.Text, x) Then 'check if this is a valid search
x = Math.Sqrt(x)
x = Math.Round(x)
e.Index = Fix(x)
End If
End Sub
This is also from the MSDN. No matter what I search for it constantly returns null.
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
Dim item1 As ListViewItem = lstAccounts.FindItemWithText(TextBox1.Text)
If (item1 IsNot Nothing) Then
MessageBox.Show("Calling FindItemWithText passing" & TextBox1.Text & ": " _
& item1.ToString())
Else
MessageBox.Show("Calling FindItemWithText passing" & TextBox1.Text & ": null")
End If
End Sub