Link to home
Start Free TrialLog in
Avatar of PeterBaileyUk
PeterBaileyUk

asked on

vb.net sendkey

I have this which does the search based on a textbox, that works great, ive added an if crossgrid.checked which if true populates the search textbox of another grid. that all goes fine but how do i replicate the pressing of the enter button on TBSearchCommon? tbsearchcommon already has a workable onkeyup event that works I just cannot see how to send an enter key for it.

i tried this but the sendkeys part didnt work
    Private Shadows Sub OnKeyUp(sender As Object, e As KeyEventArgs) Handles TxtBulkShortDesc.KeyUp
        Dim tb = DirectCast(sender, TextBox)
        If tb.Equals(TxtBulkShortDesc) Then
            If e.KeyCode.Equals(Keys.Enter) Then

                If OPCrossGrid.Checked = True Then
                    TBSearchCommon.Text = tb.Text  this part works

                    'SendKeys.Send("{Enter}") i remmed this out as it didnt work
                End If
                DataGridViewStringsBulk.SearchAndSelect(tb.Text, CBBulkSearchDesc.SelectedItem, True)
                    tb.Clear()
                    e.Handled = True
                End If
            End If

    End Sub

Open in new window

Avatar of PeterBaileyUk
PeterBaileyUk

ASKER

ok I got it to work by setting the focus

    If OPCrossGrid.Checked = True Then
                    TBSearchCommon.Focus()
                    TBSearchCommon.Text = tb.Text

                    SendKeys.Send("{Enter}")

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I refuse to give myself points so added yours as the best.
your solution worked as well, just different approach cheers