当我们在vb.net的文本框中输入一些单词时,显示从数据库到TextBox弹出窗口的相关匹配

时间:2013-03-27 13:10:41

标签: vb.net

我在Vb.net中遇到了一些问题,我在过去2天内完成了谷歌,但没有得到任何相关的问题答案,qtn就是当用户在文本框中输入一些文字时,如此相关文本如何显示弹出窗口就像当我们在Google中输入一些单词然后Google显示所有相关字段..伙伴我附加快照请帮帮我..         我使用vb.net作为后端                 和MS-Access作为前端

1 个答案:

答案 0 :(得分:0)

嘿伙计们我得到了答案 一步一步(vb.net) 1st将此声明为全局

Dim lst As New List(Of String)
Dim rdrOLEDB As OleDbDataReader
Dim MySource As New AutoCompleteStringCollection()

第2次表单加载或按照逻辑但确保它只在同一时间出现意味着不要在第3步中包含此代码(即按键)

 If ComboBox1.SelectedItem <> "" Then
        ComboBox4.Enabled = True
        cmdOLEDB.CommandText = "SELECT studentname FROM StudentDetail WHERE std = '" & ComboBox1.SelectedItem & "' "
        cmdOLEDB.Connection = cnnOLEDB
        rdrOLEDB = cmdOLEDB.ExecuteReader
        If rdrOLEDB.Read = True Then
            lst.Add(rdrOLEDB.Item(0).ToString)
            While rdrOLEDB.Read
                lst.Add(rdrOLEDB.Item(0).ToString)
            End While
        End If
        rdrOLEDB.Close()
        MySource.AddRange(lst.ToArray)
        TextBox2.AutoCompleteCustomSource = MySource

        'Auto complete mode set to suggest append so that it will sugesst one
        'or more suggested completion strings it has bith ‘Suggest’ and
        '‘Append’ functionality
        TextBox2.AutoCompleteMode = AutoCompleteMode.SuggestAppend

        'Set to Custom source we have filled already
        TextBox2.AutoCompleteSource = AutoCompleteSource.CustomSource


    Else
        MsgBox("please select std.")
    End If

第三步是文本框按键        如果e.KeyCode = Keys.Enter然后'开始输入我计划将其添加到列表中             如果不是lst.Contains(TextBox2.Text)那么'如果项目不存在                 '直接添加到源                 TextBox2.AutoCompleteCustomSource.Add(TextBox2.Text)             万一         ElseIf e.KeyCode = Keys.Delete然后'在删除键上,计划删除条目

        ' declare a dummy source
        Dim coll As AutoCompleteStringCollection = TextBox2.AutoCompleteCustomSource

        ' remove item from new source
        coll.Remove(TextBox2.Text)

        ' Bind the updates
        TextBox2.AutoCompleteCustomSource = coll

        ' Clear textbox
        TextBox2.Clear()

    End If                   ' End of ‘KeyCode’ condition

如果它的帮助满了那么请不要忘记点击其他人的搜索点(我的英语不好用我的孩子)