Here is my code for the combobox.
Option Strict Off
Option Explicit On
Imports Microsoft.Visua lBasic
Imports System
Imports System.Drawing
Imports System.Windows. Forms
Public Class MultiKeyCombo
Inherits ComboBox
'Auto complete Combo variables
Private intSaveIndex As Integer
Private blnMultiKeySele ct As Boolean = False
Public Property MultiKeySelect( ) As Boolean
Get
Return blnMultiKeySele ct
End Get
Set(ByVal Value As Boolean)
blnMultiKeySele ct = Value
End Set
End Property
Private Sub MultiKeyCombo_K eyUp(ByVal sender As Object, ByVal e As
System.Windows. Forms.KeyEventA rgs) Handles MyBase.KeyUp
If MultiKeySelect Then
'AutoComplete(C Type(sender, ComboBox), e)
Dim cbo As ComboBox = DirectCast(Me, ComboBox)
Select Case e.KeyCode
Case Keys.Back, Keys.Left, Keys.Right, Keys.Up, Keys.Delete,
Keys.Down, Keys.Tab, Keys.Shift, Keys.LShiftKey, Keys.RShiftKey, Keys.ShiftKey
Return
End Select
Dim ComboBoxText As String = cbo.Text
Dim FirstFound As Integer = cbo.FindString( ComboBoxText)
If FirstFound >= 0 Then
Dim FirstFoundItem As Object = cbo.Items(First Found)
Dim FirstFoundText As String = cbo.GetItemText (FirstFoundItem )
cbo.Text = FirstFoundText
cbo.SelectionSt art = ComboBoxText.Le ngth
cbo.SelectionLe ngth = cbo.Text.Length
'Save the last index
intSaveIndex = FirstFound
Else
'If no match is found go back to the last index and select the
'whole text
If blnMultiKeySele ct = True Then
'cbo.Text = cbo.Text.Substr ing(0, cbo.Text.Length - 1)
If intSaveIndex > 0 Then
cbo.SelectedInd ex = intSaveIndex
End If
cbo.SelectionSt art = 0
cbo.SelectionLe ngth = cbo.Text.Length ()
End If
End If
End If
End Sub
Private Sub MultiKeyCombo_L eave(ByVal sender As Object, ByVal e As
System.EventArg s) Handles MyBase.Leave
If MultiKeySelect Then
If MyBase.Text <> "" Then
'Check to make sure an invalid entry is not left in the
combobox
Dim cbo As ComboBox = DirectCast(send er, ComboBox)
Dim ComboBoxText As String = cbo.Text
Dim FirstFound As Integer = cbo.FindStringE xact(ComboBoxTe xt)
If FirstFound < 0 Then
cbo.SelectedInd ex = intSaveIndex
Else
cbo.SelectedInd ex = FirstFound
End If
End If
End If
End Sub
End Class
"Cor Ligthert" wrote:
Brian,
May I say it in otherwords, your selectedindex has another value than the
selectedvalue has?
This is than really strange,
While the combobox.textbo x gives another string than is that textbox shows?
I knof this kind of behaviour from the selectionchange commited, however you
did again not tell what events you are using for the combobox.
Cor