Hi guys need help here.
Scenario:
I have a function in my textbox1 with the got focus event. I have a 40 textbox in my goupbox1. Here is my code so far.
Private Sub Textbox1_GotFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Textbox1_GotFocus
...
...
For Each x As TextBox In Me.GroupBox1.Controls.OfType(Of TextBox)()
' Im stuck here
Next
End Sub
As you can see guys, I want that when the textbox1 gotFocus, all my textbox in groupbox1 under the for loop event will declare that only numbers are allowed to be entered in all the textbox. I manage to work with it but only in a single textbox. Here is my code for it.
Private Sub Textbox1_keypress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Textbox1.KeyPress
If e.KeyChar <> ChrW(Keys.Back) Then
If Char.IsNumber(e.KeyChar) Then
Else
MessageBox.Show("Invalid Input! Numbers Only.", "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
e.Handled = True
End If
End If
End Sub
My question is, Is there a way or would it be posibble to put this code # 2 into the code # 1? So that I don't have to declare 40 TEXTBOX which is not good. Please advise me or help me with this code.