建议datagridview上的数据匹配文本框中的数据输入 [英] suggesting data on datagridview matching the data typing in textbox

查看:62
本文介绍了建议datagridview上的数据匹配文本框中的数据输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,这是我在sql中搜索数据并将其显示到datagridview的代码。

但是我想根据我在文本框中输入的内容,在datagridview中建议可能的数据?

请帮帮我..

提前谢谢.. :)



hi guys, here's my code for seraching data in sql and display it to datagridview.
But I want to make it suggesting the possible data(s) in datagridview base on what i'm typing in the textbox?
Help me please..
Thank you in advance.. :)

<br />
<br />
 ' ''-------Search records from database<br />
        Dim cmds As New SqlCommand<br />
        Dim cons As New SqlConnection<br />
<br />
        Dim cts As String = "SELECT names,(dept + ' ' + div + ' ' + pos) as dept_div_pos, tel, local FROM directory1 where (names=@names or dept=@dept or div=@div or pos=@pos or tel=@tel or local=@local)"<br />
        cons.ConnectionString = "Data Source=192.168.xx.xx;Initial Catalog=information;Persist Security Info=True;User ID=me;Password=cute"<br />
        cmds.Connection = cons<br />
        cmds.CommandText = cts<br />
        cons.Open()<br />
<br />
        Try<br />
<br />
            If TextBox1.Text = "" Then<br />
                MsgBox("Inavalid Input!")<br />
<br />
            Else<br />
                ' ''-------- codes for textbox that can accept ascii/special characters<br />
                Dim param12 As New SqlParameter()<br />
                param12.ParameterName = "@names"<br />
                param12.Value = TextBox1.Text.Trim()<br />
                cmds.Parameters.Add(param12)<br />
                Dim param13 As New SqlParameter()<br />
                param13.ParameterName = "@dept"<br />
                param13.Value = TextBox1.Text.Trim()<br />
                cmds.Parameters.Add(param13)<br />
                Dim param14 As New SqlParameter()<br />
                param14.ParameterName = "@div"<br />
                param14.Value = TextBox1.Text.Trim()<br />
                cmds.Parameters.Add(param14)<br />
                Dim param15 As New SqlParameter()<br />
                param15.ParameterName = "@pos"<br />
                param15.Value = TextBox1.Text.Trim()<br />
                cmds.Parameters.Add(param15)<br />
                Dim param16 As New SqlParameter()<br />
                param16.ParameterName = "@tel"<br />
                param16.Value = TextBox1.Text.Trim()<br />
                cmds.Parameters.Add(param16)<br />
                Dim param17 As New SqlParameter()<br />
                param17.ParameterName = "@local"<br />
                param17.Value = TextBox1.Text.Trim()<br />
                cmds.Parameters.Add(param17)<br />
<br />
                Dim dss As New DataSet<br />
                Dim das As New SqlDataAdapter(cmds)<br />
                das.Fill(dss, "directory1")<br />
                DataGridView1.DataSource = dss<br />
                DataGridView1.DataMember = "directory1"<br />
            End If<br />
<br />
        Catch ex As Exception<br />
            MsgBox("Invalid Input")<br />
            MessageBox.Show(ex.Message)<br />
<br />
        End Try<br />
        cons.Close()<br />
<br />

推荐答案

你可以在 TextChanged 事件上完成



you can do it on TextChanged event

Private Sub TextBox1_TextChanged(sender As Object, _ 
  e As EventArgs) Handles TextBox1.TextChanged
    ' your code goes here .....
End Sub







引用:

要创建一个新的TextChanged事件,请打开Visual Studio,然后按照以下步骤操作。



单击TextBox并将其聚焦以查看正确的设计器UI。在右下角,您应该看到属性窗格。在窗格中查找闪电图标。找到闪电后,点击它。



向下滚动到TextChanged出现的位置。双击TextChanged标签旁边的空格。

To make a new TextChanged event, open Visual Studio—and follow these steps.

Click on the TextBox and focus it to see the correct designer UI. On the right bottom, you should see the Properties pane. Look for the lightning bolt icon in the pane. After you find the lightning bolt, click on it.

Scroll down to where the word TextChanged appears. Double-click in the space next to the TextChanged label.


这篇关于建议datagridview上的数据匹配文本框中的数据输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆