自动完成的combobox
根据论坛中相关的文章,我得到以下的代码,只能文本自动完成,但是索引不能自动完成,大家来看看吧,(自动完成的combobox)
Public Sub ComboAutoCom(ByVal cob As ComboBox)
Dim sTypedText As String
Dim iFoundIndex As Integer
Dim oFoundItem As Object
Dim sFoundText As String
Dim sAppendText As String
'Get the Typed Text and Find it in the list
sTypedText = cob.Text
iFoundIndex = cob.FindString(sTypedText)
'If we found the Typed Text in the list then Autocomplete
If iFoundIndex >= 0 Then
'Get the Item from the list (Return Type depends if Datasource was bound
' or List Created)
oFoundItem = cob.Items(iFoundIndex)
'Use the ListControl.GetItemText to resolve the Name in case the Combo
' was Data bound
sFoundText = cob.GetItemText(oFoundItem)
'Append then found text to the typed text to preserve case
sAppendText = sFoundText.Substring(sTypedText.Length)
cob.Text = sTypedText.ToString & sAppendText.ToString
'cob.SelectedIndex = iFoundIndex '这句是我加的,好像不起作用
'Select the Appended Text
cob.SelectionStart = sTypedText.Length
cob.SelectionLength = sAppendText.Length
End If
End Sub