新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
VB.NET添加自動查詢功能實現(xiàn)技巧概述
VB.NET編程語言的應用范圍非常廣泛,比如對文本的操作,或者在程序中添加各種文本框,對數(shù)據(jù)庫的操作等等。今天大家將會了解到有關VB.NET添加自動查詢功能的實現(xiàn)方法,以此加深大家對VB.NET這一語言的認知程度。#t#

網(wǎng)站建設哪家好,找創(chuàng)新互聯(lián)公司!專注于網(wǎng)頁設計、網(wǎng)站建設、微信開發(fā)、小程序制作、集團企業(yè)網(wǎng)站建設等服務項目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了恒山免費建站歡迎大家使用!
在窗體中添加如下方法實現(xiàn)VB.NET添加自動查詢功能:
***個方法是AutoCompleteKeyUp,它將組合框和KeyEventArgs對象作為參數(shù),需要在組合框的KeyUp事件中調用此方法;它全根據(jù)用戶輸入的內容選擇最接近的內容;
第二個方法是AutoCompleteLeave,在激活組合框的Leave事件時調用,此方法僅提取用戶最終選擇的內容,按照組合框中的每個匹配內容修改其大小寫。
VB.NET添加自動查詢功能的代碼如下:
- 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
VB.NET添加自動查詢功能相關操作方法就為大家介紹到這里。
新聞名稱:VB.NET添加自動查詢功能實現(xiàn)技巧概述
URL鏈接:http://www.5511xx.com/article/dpjhhpc.html


咨詢
建站咨詢
