我有一个小程序,在表单加载时针对对象模型运行,并使用来自系统中所有客户端的公司代码预加载组合框。
我想知道我是否可以这样做,以便用户可以开始输入公司代码,然后根据公司代码预先自动填充或匹配他们输入的内容,而不是从其中一个下拉公司中选择加载到dropown。
以下是我目前拥有的代码示例。
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
答案 0 :(得分:0)
将AutoCompleteMode
更改为Suggest
。这是ComboBox的一个属性。另外,请务必将AutoCompleteSource
更改为ListItems
,将使用自己的项目列表作为自动完成源。
http://msdn.microsoft.com/en-us/library/system.windows.forms.autocompletemode.aspx