Creating a dynamical AutoComplete textbox
November 14, 2007
In my recent project we have had to implement a own textbox to be able to set a few properties that force the user to follow certain formats etc. A few days ago I saw this as an oppurtunity to do something cool as an additional feature.
I wanted to implement a AutoComplete feature but with the values that the user has typed in this field before. It turns out that this is fairly easy to do, since AutoComplete is a property on the TextBox control in the .NET Framework. Here is a nice video that introduce the concepts surrounding AutoCompletion
So how did I do it then? First I added a handling of the Resize-event that sets the autoComplete-properties.
Me.AutoCompleteMode = Windows.Forms.AutoCompleteMode.Suggest Me.AutoCompleteSource = Windows.Forms.AutoCompleteSource.CustomSource Me.AutoCompleteCustomSource = State.HamtaAutoCompleteLista(Me.Name)
State.HamtaAutoCompleteLista is a function that returns the AutoCompleteStringCollection that should be used for the control.
As you might notice...