[英]auto-fill from combobox when typing into textbox
I have a small program that upon form load runs against an object model and pre-loads a combobox with companycodes from all of our clients in the system. 我有一个小程序,在窗体加载时会针对对象模型运行该程序,并使用系统中所有客户的公司代码预加载组合框。
I'm wondering if i can make it so that instead of choosing from one of the dropdown companies the user can just start typing in the company code and have the box autofill or match what they type based on the company codes pre-loaded into the dropown. 我想知道我是否可以做到这一点,而不是从下拉列表公司中选择一家,用户只需开始输入公司代码并自动填写框或根据他们预先输入的公司代码来匹配他们键入的内容即可。垂头丧气。
Here is a sample of the code that i currently have. 这是我当前拥有的代码示例。
Imports System.IO
Public Class MainForm
Dim g_System As MILLSYSTEMLib.System
Public Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'On Error Resume Next
Try
Dim Approved As Integer
' Create a Millennium system obects
g_System = CreateObject("MillSystem.System")
Dim User As Object = g_System.Login()
' See if login worked
If User Is Nothing Then
MsgBox("Login failed!")
Approved = 0
Else
'MsgBox("Login successful")
'if approved=1 then the user is able to access M3
Approved = 1
End If
'populate combo box
For Each Company In g_System.Companies
cb_COID.Items.Add(Company.Field("co").ToString)
Next
Catch ex As Exception
Me.Close()
End Try
End Sub
Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
'get value of combo boxes
Dim COID, Year As String
If cb_COID.SelectedItem = True Then
COID = cb_COID.SelectedItem
Else
COID = cb_COID.Text
End If
If cb_Year.SelectedItem = True Then
Year = cb_Year.SelectedItem
Else
Year = cb_Year.Text
End If
If IsNothing(COID) Then
MessageBox.Show("Select a Company Code")
ElseIf IsNothing(Year) Then
MessageBox.Show("Select a Year")
Exit Sub
End If
If rb_Storeroom.Checked = True Then
ofd_Storeroom.InitialDirectory = "\\site\M3\Storeroom\" + COID + "\" + Year + "\"
ofd_Storeroom.Filter = "Employer W2 Files | *ER_W2.mdoc"
ofd_Storeroom.ShowDialog()
ElseIf rb_Archive.Checked = True Then
ofd_Storeroom.InitialDirectory = "\\site\M3\Archive\Storeroom\" + Year + "\" + COID + "\" + Year + "\"
ofd_Storeroom.Filter = "Employer W2 Files | *ER_W2.mdoc"
ofd_Storeroom.ShowDialog()
Else
MessageBox.Show("Select a Directory")
Exit Sub
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub ofd_Storeroom_FileOk(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles ofd_Storeroom.FileOk
If rb_Storeroom.Checked = True Then
tb_Storeroom.Text = ofd_Storeroom.FileName
ElseIf rb_Archive.Checked = True Then
tb_Archive.Text = ofd_Storeroom.FileName
End If
ofd_Storeroom.FileName = ""
End Sub
Private Sub btn_ViewFile_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_ViewFile.Click
Dim StoreSource As String = tb_Storeroom.Text
Dim ArchSource As String = tb_Archive.Text
Dim Temp As String = "\\site\M3\Test\W2\"
Dim fName As String = Path.GetFileName(StoreSource)
Dim fName2 As String = Path.GetFileName(ArchSource)
If rb_Storeroom.Checked = True Then
File.Copy(StoreSource, Path.Combine(Temp, fName), True)
ElseIf rb_Archive.Checked = True Then
File.Copy(ArchSource, Path.Combine(Temp, fName2), True)
End If
Dim p As New Process
Dim psi As New ProcessStartInfo("C:\program files\7-zip\7z", "x" & " " & Temp & " " & "-o" & "-y" & Temp)
p.StartInfo = psi
p.Start()
p.WaitForExit()
If rb_Storeroom.Checked = True Then
Process.Start(Temp + fName + ".pdf")
ElseIf rb_Archive.Checked = True Then
Process.Start(Temp + fName2 + ".pdf")
End If
fName = ""
fName2 = ""
End Sub
Private Sub btn_nwsrch_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_nwsrch.Click
Dim Temp As String = "\\site\M3\Test\W2"
Try
For Each tb In Me.Controls.OfType(Of TextBox)()
tb.Text = String.Empty
Next tb
For Each rb In Me.Controls.OfType(Of RadioButton)()
rb.Checked = False
Next rb
For Each cb In Me.Controls.OfType(Of ComboBox)()
cb.Text = String.Empty
Next cb
For Each filename As String In IO.Directory.GetFiles(Temp)
IO.File.Delete(filename)
Next
Catch ex As Exception
MessageBox.Show("You must close the PDF first")
Exit Sub
End Try
End Sub
Sub frmMain_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Dim Temp As String = "\\site\M3\Test\W2"
Try
For Each filename As String In IO.Directory.GetFiles(Temp)
IO.File.Delete(filename)
Next
Catch ex As Exception
MessageBox.Show("You must close the PDF first")
Exit Sub
End Try
End Sub
End Class
Change the AutoCompleteMode
to Suggest
. 更改AutoCompleteMode
给Suggest
。 This is a property of the ComboBox. 这是ComboBox的属性。 Also make sure to change the AutoCompleteSource
to ListItems
, that will use its own list of items as the AutoComplete source. 另外,还要确保将AutoCompleteSource
更改为ListItems
,它将使用其自己的项目列表作为AutoComplete源。
http://msdn.microsoft.com/en-us/library/system.windows.forms.autocompletemode.aspx http://msdn.microsoft.com/zh-CN/library/system.windows.forms.autocompletemode.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.