roy
roy

Reputation: 729

How to use binding source filter from one TextBox and Show to another TextBox in vb.net

I have 2 Textboxes namely TextBoxITC and TextBoxITM. So I've created a keydown event in TextBoxITC so I want to show the result of "ITM" Column in textboxITM.

Thanks

 Dim source1 As New BindingSource()
 Private Sub PopulateDatatable()
        Try
            Dim query As String = "Select ITC,ITM FROM IFG WHERE GDN = 'A.04.01.002.001'"
            Using con As OleDbConnection = New OleDbConnection(cn)
                Using cmd As OleDbCommand = New OleDbCommand(query, con)
                    Using da As New OleDbDataAdapter(cmd)
                        Dim dt As DataTable = New DataTable()
                        da.Fill(dt)
                        da.Dispose()
                        source1.DataSource = dt
                    End Using
                End Using
            End Using
        Catch myerror As OleDbException
            MessageBox.Show("Error: " & myerror.Message)
        Finally
        End Try
    End Sub
 Private Sub TextBoxITC_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBoxITC.KeyDown
        If e.KeyCode = Keys.Back Then
            source1.Filter = ""
            TextBoxITC.Clear()
            clearData()
        Else
        End If
        If e.KeyCode = Keys.Enter Then
            source1.Filter = "ITC = '" & Replace(TextBoxITC.Text, "'", "") & "'"

            If source1.Count <= 0 Then
                source1.Filter = ""
                TextBoxITC.Clear()
                MsgBox("No Result Found!", MsgBoxStyle.Exclamation)
            End If
        End If
    End Sub

Upvotes: 0

Views: 149

Answers (1)

roy
roy

Reputation: 729

Here's a link! and Answer from @Steve

 Private Sub TextBoxITC_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBoxITC.KeyDown
        If e.KeyCode = Keys.Back Then
            source1.Filter = ""
            TextBoxITC.Clear()
            clearData()
        Else
        End If
        If e.KeyCode = Keys.Enter Then
              Using con As OleDbConnection = New OleDbConnection(cn)
                con.Open()
                Dim query As String = "Select ITM FROM IFG WHERE ITC = ? AND GDN = 'A.04.01.002.001'"
                Using command As OleDbCommand = New OleDbCommand(query, con)

                    command.Parameters.Add("ITC", OleDbType.VarChar).Value = TextBoxITC.Text
                    Dim result As Object = command.ExecuteScalar()
                    If result IsNot Nothing Then
                        TextBoxolditem.Text = result.ToString()
                    Else
                        TextBoxolditem.Text = "Number Not found!"
                    End If
                    con.Close()
                End Using
            End Using
        End If
    End Sub

Upvotes: 0

Related Questions