473,403 Members | 2,222 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

OnTextChanged combobox overrides

I found some code in Google, don't remember where, for an AutoComplete
combobox. Everything is great with it except for one thing. If I use
the mouse to drop the list down, then start typing to find the item in
the list, the visible text changes, but the values of me.Text and
Mybase.Text do not change. If you use the mouse and actually click on
the item, the values of me.text and Mybase.Text will change. Or, if
you use the enter key to move focus to the next box the value of Text
will be updated. Is there something I am doing wrong here. I thought
the visible text you are seeing on the screen would have to be the
value of MyBase.Text. Since they aren't the same value, how is the
visible Text being stored to be able to display it on the screen?

Any help will be very appreciated.

Thanks
Kalvin
'****** begin code *******

Option Strict On

Imports System.ComponentModel

Public Class ComboBoxAutoComplete
Inherits System.Windows.Forms.ComboBox

Private m_isAutoCompleteSuspended As Boolean = False
Private m_strOriginal As String

#Region "Properties"
Private m_Autocomplete As Boolean = True

<Description("Enable or disable the autocomplete feature"),
Category("Behavior")> _
Public Property Autocomplete() As Boolean
Get
Return m_Autocomplete
End Get
Set(ByVal Value As Boolean)
m_Autocomplete = Value
If m_Autocomplete Then
Me.DropDownStyle = ComboBoxStyle.DropDown
End If
End Set
End Property

#End Region

#Region "Overrides"
Protected Overrides Sub OnTextChanged(ByVal e As System.EventArgs)

If Me.m_Autocomplete Then

If Not Me.m_isAutoCompleteSuspended Then

Dim index As Integer
Dim strlength As Integer

' Retrieve the current text's length
strlength = Me.Text.Length

' Try to find the match in the list
index = Me.FindString(Me.Text)

If index > -1 Then

' A match is found. Select it.
Me.SelectedIndex = index
Me.SelectionStart = strlength
Me.SelectionLength = Me.Text.Length

Me.Refresh()
End If

End If
End If

MyBase.OnTextChanged(e)

End Sub

Protected Overrides Sub OnKeyDown(ByVal e As
System.Windows.Forms.KeyEventArgs)

If Me.m_Autocomplete Then
Select Case e.KeyData
Case Keys.Back
If Me.SelectionStart > 0 Then
Me.SelectionStart -= 1
Me.SelectionLength += 1
Me.m_isAutoCompleteSuspended = True

End If

Case Keys.Escape
Me.m_isAutoCompleteSuspended = False
Me.Text = Me.m_strOriginal
Me.SelectAll()
Me.m_isAutoCompleteSuspended = True

Case Else
Me.m_isAutoCompleteSuspended = False

End Select

End If

MyBase.OnKeyDown(e)

End Sub

Protected Overrides Sub OnGotFocus(ByVal e As System.EventArgs)

If Me.m_Autocomplete Then
Me.m_strOriginal = Me.Text

End If

MyBase.OnGotFocus(e)

End Sub

Protected Overrides Sub OnLostFocus(ByVal e As System.EventArgs)

If Me.m_Autocomplete Then
Me.m_strOriginal = Nothing

' Me.SelectedIndex = me.selectedindex
MyBase.SelectedIndex = Me.SelectedIndex

End If

MyBase.OnLostFocus(e)

End Sub

Protected Overrides Sub OnValidating(ByVal e As
System.ComponentModel.CancelEventArgs)

If Me.m_Autocomplete Then
Dim index As Integer

If Me.Text = "" Then
Me.SelectedIndex = -1

Else
' Try to find the match in the list
index = Me.FindStringExact(Me.Text)

If index = -1 Then
' No match is found. Ask user whether to add it
Me.OnNoMatchFound(e)

Else
' A match is found. Select it
Me.SelectedIndex = index

End If

End If

End If

MyBase.OnValidating(e)

End Sub

#End Region

Public Delegate Sub NoMatchFoundEventHandler(ByVal sender As
System.Object, ByVal e As System.ComponentModel.CancelEventArgs)
Public Event NoMatchFound As NoMatchFoundEventHandler

Protected Overridable Sub OnNoMatchFound(ByVal e As
System.ComponentModel.CancelEventArgs)
RaiseEvent NoMatchFound(Me, e)
End Sub

End Class

Nov 21 '05 #1
2 2203
Additional note about this. It appears to only happen when the
combobox is bound.

Kalvin

Nov 21 '05 #2
Is there somewhere I can post this that someone may know what I can do
about this?

Kalvin

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: ross kerr | last post by:
Hi All, I am extending the combobox to create a control that selects an item based on the text the user is typing into the text area of the control. I have an issue that occurs only when i...
5
by: jaYPee | last post by:
i have successfully added a combobox to my datagrid by setting their datasource from one of my table. here's my code... Dim grdColStyle6 As New DataGridComboBoxColumn() With grdColStyle6...
2
by: pmcguire | last post by:
I have derived a ComboBoxColumnStyle that inherits DataGridColumnStyle. It works fine except for one behavior. If the user selects a new value from the ComboBox's pulldown list on a brand new...
9
by: Don | last post by:
Is there any way to detect when an item has been added to the Items collection of a combobox or listbox? I am inheriting a Combobox and want to validate items before they are added to the...
2
by: Don | last post by:
I've looked high and low for some code that will allow me to have a combobox with a flat borderstyle. I found a few examples, but nothing that was really usable for me. I had the following...
30
by: dbuchanan | last post by:
ComboBox databindng Problem == How the ComboBox is setup and used: My comboBox is populated by a lookup table. The ValueMember is the lookup table's Id and the DisplayMember is the text from a...
1
by: fiaolle | last post by:
Hi The first set of source code is the class for a combobox in a grid, hopefully. In the second set of code we try to use the combobox class, but the grid is empty. I don't understand how this...
5
by: active | last post by:
I tried to use a datasource with a combobox and it didn't work completely so I build a small test that was much more straight forward then the app. The test was to see if the combobox dropdown...
8
by: =?Utf-8?B?RyBIdXN0aXM=?= | last post by:
This is the 2nd time posting so sorry for duplications. I am using VB.NT 2005 & a standard Combobox. I've been wracking my brain over this problem for a over a month & cannot seem to find a way to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.