Is this doable? I have a textbox for email address entry, now, when I type the email address and reach the @ character, there will be a dropdown suggesting common domains like msn.com,hotmail.com, aol.com, yahoo.com and etc.
I hope you can help me. Thanks in advance.
Sure it is doable! You just have to code it. :))
Here is a crude implementation of a custom textbox with this capability. You have to double click on a item to select it. You could change that to single click if you want. You may need to change the "@" detection algorithm. It works with a standard US keyboard with "@" = shift-2.
There is no error checking; I leave that to you.
Public Class AutoCompleteDropDownTB Inherits TextBox Public WithEvents dropdown As New ListBox Private frmDropDown As New Form Public Sub New() dropdown.Parent = frmDropDown dropdown.SelectionMode = SelectionMode.One With frmDropDown .FormBorderStyle = FormBorderStyle.None .Size = dropdown.Size .Visible = False .StartPosition = FormStartPosition.Manual .TopLevel = True .TopMost = True End With End Sub Protected Overrides Sub OnKeyDown(ByVal e As System.Windows.Forms.KeyEventArgs) If e.Shift AndAlso e.KeyCode = Keys.D2 AndAlso Not Text.Contains("@"c) Then ShowDropDown() End If MyBase.OnKeyDown(e) End Sub Private Sub ShowDropDown() dropdown.SelectedIndex = 0 ' make sure 1st item is selected Dim offset As Int32 If BorderStyle = Windows.Forms.BorderStyle.Fixed3D Then offset = 2 Else offset = 0 End If With frmDropDown .Location = PointToScreen(New Point(0, Size.Height - offset)) .Show() End With End Sub Private Sub dropdown_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles dropdown.DoubleClick frmDropDown.Hide() Text &= dropdown.SelectedItem.ToString SelectionStart = TextLength End Sub Private Sub dropdown_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles dropdown.LostFocus frmDropDown.Hide() End Sub End Class
Just add this to your project and rebuild. It should show up at the top of your toolbox.
Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ' add the dropdown list items With AutoCompleteDropDownTB1.dropdown.Items .Add("fred.com") .Add("wilma.com") .Add("barney.com") End With End Sub End Class
Great code TnTinMN, thank you so much. This is now solved.
Hi, as I was told that my code doesn’t scale well at all, I thought perhaps I’d try to get a better understanding of interfaces/abstract classes and classes and the relationship between them.
I don’t want at this stage work on a big separate project as I've already got plenty ...
OK, so HostGator for some reason no longer allows gcc/g++ access unless you have a Designated Server account, which is a lot of money to spend just to compile my "Hello World" program. Thus I figured I'd compile at home, then upload. Program is your regular old bare-bones Hello World ...
Hi. I have a form with list box : lst_product, datagridview : grd_order and button: btn_addline. lst_product has a list of product ids selected from database (MS Acess 2013) , grd_order is by default empty except for 2 headers and btn_addline adds rows to grd_order.
Private Sub btn_addline_Click(ByVal ...