Not sure if you already figured it out but....
I initially thought u wanted the items highlighted with a custom color.. Which i thought would be cake...
Errr.. not for me lmao..
But I found a post for that if your interested and i made a working model of the thing you were trying to accomplish..
I used Edgemeal idea for esc & backspace.. Tried to incorporate the color thing but i couldnt get it..
Note: If you do attempt to do the color thing there is a mis-type i believe on line 41 of the colorListbox class.. It read itemDate which I'm sure shouldve been itemData..
Here's da post on the colorlist:
http://www.vbforums.com/showthread.p...ow-With-Class!
I did include it in solution already..
Heres the code:
Code:
Private catchKey As New KeyPressEventHandler(AddressOf GetKeyPress)
Private searchTerm As String = Nothing
Private Sub GetKeyPress(sender As System.Object, ByVal e As KeyPressEventArgs)
'Check for the back key
If Asc(e.KeyChar) = 8 And Not IsNothing(searchTerm) Then
searchTerm = searchTerm.Remove(searchTerm.Count - 1, 1)
'Check for the escape key
ElseIf Asc(e.KeyChar) = 27 Then
ClearListBox(sender, System.EventArgs.Empty)
End If
'Check to see we have a character and not something like capslock
If Asc(e.KeyChar) > 33 And Asc(e.KeyChar) < 126 Then
If IsNothing(searchTerm) Then
searchTerm = e.KeyChar
Else
If searchTerm.Count = 3 Then
searchTerm = Nothing
GetKeyPress(sender, e)
Exit Sub
End If
searchTerm &= e.KeyChar
End If
End If
Me.CurSrchTrm_Label.Text = searchTerm
highlightSearch(searchTerm)
End Sub
Private Sub Form1_Click(sender As System.Object, e As System.EventArgs) Handles MyBase.Click
Val2SrchBrdr_Panel.Focus()
End Sub
Private Sub ClearListBox(sender As System.Object, e As System.EventArgs) Handles ResetListBox_But.Click
Me.Vals2Srch_ListBox.Items.Clear()
searchTerm = Nothing
End Sub
Private Sub AddNewVal_But_Click(sender As System.Object, e As System.EventArgs) Handles AddNewVal_But.Click
Me.Vals2Srch_ListBox.Items.Add(Me.NewVals_TxtBox.Text)
Me.NewVals_TxtBox.Text = Nothing
End Sub
Private Sub Vals2Srch_ListBox_Focus(sender As System.Object, e As System.EventArgs) Handles Vals2Srch_ListBox.GotFocus
Me.Val2SrchBrdr_Panel.BackColor = Color.Red
AddHandler Me.Vals2Srch_ListBox.KeyPress, catchKey
End Sub
Private Sub Vals2Srch_ListBox_NoFocus(sender As System.Object, e As System.EventArgs) Handles Vals2Srch_ListBox.LostFocus
Me.Val2SrchBrdr_Panel.BackColor = Color.FromKnownColor(KnownColor.Control)
RemoveHandler Me.Vals2Srch_ListBox.KeyPress, catchKey
End Sub
'Credit: http://www.vbforums.com/showthread.php?578364-Colored-ListBox-(custom-fonts-colors-highlight)-Updated!-Now-With-Class!
'Private Sub highlightSearch(ByVal searchStr As String)
' For Each itemObj As ItemData In Me.Vals2Srch_ListBox.Items
' If Not (itemObj.Item.ToLower.IndexOf(searchTerm.ToLower) = -1) Then
' itemObj.ItemColor = Color.Yellow
' End If
' Next
'End Sub
Private Sub highlightSearch(ByVal searchStr As String)
Dim itemsSelectedList As New ArrayList
Dim itemIndex As Integer = 0
TestList_ListBox.Items.Clear()
For Each itemObj As String In Me.Vals2Srch_ListBox.Items
If Not (itemObj.ToLower.IndexOf(searchStr.ToLower) = -1) Then
TestList_ListBox.Items.Add(itemObj)
itemsSelectedList.Add(itemIndex)
'itemObj.ItemColor = Color.Yellow
End If
itemIndex += 1
Next
Me.Vals2Srch_ListBox.SelectedItem = Nothing
For Each i As Integer In itemsSelectedList
Me.Vals2Srch_ListBox.SetSelected(i, True)
Next
End Sub
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Me.CurSrchTrm_Label.Text = Nothing
End Sub