Hey,
I'm having a problem where the Button.PerformClick() method sometimes isn't firing the Click event of the button in question. This is kind of a long post, but I would like to explain everything.
The weird thing is that I only have the issue in a certain scenario:
I have a textbox, and a button next to it. The button allows the user to search for data, and then select this data to put it in the textbox.
On the other hand, the user can just enter the data in the textbox, and validate it by changing focus (i.e. textbox_validating method is called), or by calling the shortcut to/clicking the button (Shortuct is F2).
If the data entered in the textbox is not valid, the validating method will tell the user there's an error, set the focus back on the textbox, and then select all the text in it.
This problem only occurs when the following happens:
1- User enters invalid text, changes focus => Error shown to user, and textbox has focus again.
2- User removes all text, then clicks on F2, the shortcut to the button, but nothing hapens.
Here's a snippet of the code in question.
I followed the code, and everything is fine when the user presses on F2. The problem is that when the btnRechFou.PerformClick() is reached, the application doesn't step into btnRechFou_Click().
Clicking the button manually works fine.
It's a small problem, but for the life of me, I can't seem to figure out what the problem is. Does anyone have any ideas?
Thanks.
I'm having a problem where the Button.PerformClick() method sometimes isn't firing the Click event of the button in question. This is kind of a long post, but I would like to explain everything.
The weird thing is that I only have the issue in a certain scenario:
I have a textbox, and a button next to it. The button allows the user to search for data, and then select this data to put it in the textbox.
On the other hand, the user can just enter the data in the textbox, and validate it by changing focus (i.e. textbox_validating method is called), or by calling the shortcut to/clicking the button (Shortuct is F2).
If the data entered in the textbox is not valid, the validating method will tell the user there's an error, set the focus back on the textbox, and then select all the text in it.
This problem only occurs when the following happens:
1- User enters invalid text, changes focus => Error shown to user, and textbox has focus again.
2- User removes all text, then clicks on F2, the shortcut to the button, but nothing hapens.
Here's a snippet of the code in question.
VB.NET:
Public Overrides Sub FormKeyDown(ByVal sender As Object, _
ByVal e As System.Windows.Forms.KeyEventArgs)
If e.KeyCode = Windows.Forms.Keys.F2 Then
Select Case ActiveControl.Name.ToUpper
Case "TXTCODE"
btnSearch.PerformClick()
Case "TXTSUPPLIER"
btnRechFou.PerformClick() 'Problem is here
'btnRechFou_Click(Me, New System.EventArgs)
End Select
Else
MyBase.FormKeyDown(sender, e)
End if
End Sub
Private Sub btnRechFou_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRechFou.Click
'Some code here
End Sub
I followed the code, and everything is fine when the user presses on F2. The problem is that when the btnRechFou.PerformClick() is reached, the application doesn't step into btnRechFou_Click().
Clicking the button manually works fine.
It's a small problem, but for the life of me, I can't seem to figure out what the problem is. Does anyone have any ideas?
Thanks.