-1

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

4

1 回答 1

0

嘿伙计们,我得到了答案一步一步(vb.net)第一次宣布这是一个全球性的

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

第二次加载表单或根据您的逻辑,但确保它只出现一次意味着不要在第三步中包含此代码(即按键)

 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

第三步是文本框按键 If e.KeyCode = Keys.Enter Then ' On enter 我计划将它添加到列表 If Not lst.Contains(TextBox2.Text) Then ' If item not present already ' 直接添加到源TextBox2.AutoCompleteCustomSource.Add(TextBox2.Text) End If ElseIf e.KeyCode = Keys.Delete Then '在删除键上,计划删除条目

        ' 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

如果它的帮助已满,请不要忘记点击其他人的搜索点(请原谅我的英语不好)

于 2013-03-28T14:23:27.713 回答