部分词搜索VB.Net

时间:2015-10-15 20:22:42

标签: vb.net datagridview

我在文本框的TextChanged例程中使用以下代码段来搜索数据网格视图并根据结果进行过滤。这仅在搜索的项目与键入的文本的顺序相同时才有效。例如,要搜索Green Apple,我必须输入Green Apple,因为我只想输入Apple。有没有办法进行中间词搜索?

 source1.Filter = String.Format("{0} LIKE '{1}%'", "Description", SearchBx.Text)

查询代码以填充datagrid

         toLoad = cbDisplay.Text & ".csv"

        Dim odf As String = "C:\Dropbox\Queries\Cats\" & toLoad


        Dim sConnectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=""" & Path.GetDirectoryName(odf) & """;Extended Properties=""Text;HDR=Yes;FORMAT=Delimited"";"


        Dim objConn As New OleDbConnection(sConnectionString)
        objConn.Open()
        Dim objCmdSelect As New OleDbCommand("SELECT [PID], [Tertiary Category], ([Brand] + ' ' + [Description]) as Description, [Pack Description] FROM " & odf, objConn)
        Dim objAdapter1 As New OleDbDataAdapter

        objAdapter1.SelectCommand = objCmdSelect
        Dim objDataset1 As New DataSet


        objAdapter1.Fill(objDataset1, "test")
        DataGridView1.DataSource = objDataset1.Tables(0).DefaultView

        objConn.Close()

        DataGridView1.Columns(0).HeaderCell.Value = "PID"
        DataGridView1.Columns(1).HeaderCell.Value = "Tertiary"
        DataGridView1.Columns(2).HeaderCell.Value = "Description"
        DataGridView1.Columns(3).HeaderCell.Value = "Pack Size"
        DataGridView1.Columns(2).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        DataGridView1.Columns(3).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
        DataGridView1.Columns(3).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
        DataGridView1.Columns(0).ReadOnly = True
        DataGridView1.Columns(1).ReadOnly = True
        DataGridView1.Columns(3).SortMode = DataGridViewColumnSortMode.Automatic

        Dim columnwidth1 As DataGridViewColumn = DataGridView1.Columns(0)
        columnwidth1.Width = 94
        Dim columnwidth2 As DataGridViewColumn = DataGridView1.Columns(1)
        columnwidth2.Width = 125
        Dim columnwidth3 As DataGridViewColumn = DataGridView1.Columns(2)
        columnwidth3.Width = 240
        Dim columnwidth4 As DataGridViewColumn = DataGridView1.Columns(3)
        columnwidth4.Width = 94

        source1.DataSource = objDataset1.Tables(0).DefaultView

0 个答案:

没有答案