当前位置:首页 > 网络编程 > WEB编程 > ASP.net > .NET中为组合框添加自动查询功能

.NET中为组合框添加自动查询功能

点击次数:56 次 发布日期:2008-11-21 22:06:44 作者:源代码网
源代码网推荐

源代码网整理以下在窗体中添加如下方法:

源代码网整理以下第一个方法是AutoCompleteKeyUp,它将组合框和KeyEventArgs对象作为参数,需要在组合框的KeyUp事件中调用此方法;它全根据用户输入的内容选择最接近的内容;

源代码网整理以下第二个方法是AutoCompleteLeave,在激活组合框的Leave事件时调用,此方法仅提取用户最终选择的内容,按照组合框中的每个匹配内容修改其大小写。

源代码网整理以下代码如下:

源代码网整理以下

以下为引用的内容:

源代码网整理以下  Private Sub AutoCompleteKeyUp(ByVal Combo As ComboBox, ByVal e As KeyEventArgs)

源代码网整理以下  Dim strTyped As String

源代码网整理以下  Dim intFoundIndex As Integer

源代码网整理以下  Dim objFoundItem As Object

源代码网整理以下  Dim strFoundText As String

源代码网整理以下  Dim strAppendText As String

源代码网整理以下  "忽略特殊键

源代码网整理以下  Select Case e.KeyCode

源代码网整理以下  Case Keys.Back, Keys.Left, Keys.Right, Keys.Up, Keys.Down, Keys.Delete, Keys.CapsLock

源代码网整理以下  Return

源代码网整理以下  End Select

源代码网整理以下  "在查询列表中找到

源代码网整理以下  strTyped = Combo.Text

源代码网整理以下  intFoundIndex = Combo.FindString(strTyped)

源代码网整理以下  If intFoundIndex >= 0 Then

源代码网整理以下  objFoundItem = Combo.Items(intFoundIndex)

源代码网整理以下  strFoundText = Combo.GetItemText(objFoundItem)

源代码网整理以下  strAppendText = strFoundText.Substring(strTyped.Length)

源代码网整理以下  Combo.Text = strTyped & strAppendText

源代码网整理以下  Combo.SelectionStart = strTyped.Length

源代码网整理以下  Combo.SelectionLength = strAppendText.Length

源代码网整理以下  End If

源代码网整理以下  End Sub

源代码网整理以下  Private Sub AutoCompleteLeave(ByVal Combo As ComboBox)

源代码网整理以下  Dim intFoundIndex As Integer

源代码网整理以下  intFoundIndex = Combo.FindStringExact(Combo.Text)

源代码网整理以下  Combo.SelectedIndex = -1

源代码网整理以下  Combo.SelectedIndex = intFoundIndex

源代码网整理以下  End Sub

源代码网整理以下  Private Sub ComboBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ComboBox1.KeyUp

源代码网整理以下  AutoCompleteKeyUp(ComboBox1, e)

源代码网整理以下  End Sub

源代码网整理以下  Private Sub ComboBox1_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles ComboBox1.Leave

源代码网整理以下  AutoCompleteLeave(ComboBox1)

源代码网整理以下  End Sub

源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华