I have defined a procedure under the click event of the button as follows.

Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
        'Validate Department
        If cmbDepartment.SelectedItem = Nothing Then
            MsgBox("Please select a department", MsgBoxStyle.Information, "Notification")
            Exit Sub
        End If
End Sub

I want to call this procedure when press on the enter key

Private Sub txtSearchValue_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtSearchValue.KeyPress
If Asc(e.KeyChar) = 13 Then

MsgBox("Run the btnSearch click event")

End If
End sub

Can anyone suggest me a way to do this???????
Would be a great help

7 Years
Discussion Span
Last Post by chickss

Please use code tags in the future

<- Remove the spaces and it will work
code here

To answer your question you should move the functionality to another method instead of calling the button's click event, but:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		Button2_Click(sender, New System.EventArgs())
	End Sub

	Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
		MessageBox.Show("I called button2 from button1")
	End Sub

That was cool.. it works but when i call button click event
it does not do all things on the button1 event. for example

msgbox "Boom"
Call loadmyData 'this thing didnt fire

button1_click(sender, new system.eventargs())

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.