G
Guest
Hi to all,
I am having a problem while trying to assign an event to a generated textbox control. This textbox is generated dynamically, its a variable which name is "txtCamp", for this variable I generate a certain number of instances in the layout screen in some differents positions, to have a binding to the database fields.These textboxes have a different property "Name" assigned dynamically to distinguish them. Then I add a new Event Handler which responds to the "KeyDown" event of the textbox. My problem comes when I want to distinguish between all the "KeyDown" Events of these instances of the variable "txtCamp". The code added to the "KeyDown" event is the typical one:
Private Sub txtCamp_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtCamp.KeyDown
txtCamp.BackColor = System.Drawing.Color.Gold
btModify.Enabled = False
btDelete.Enabled = False
End Sub
The event handlet is added normally like this:
AddHandler txtCamp.KeyDown, AddressOf txtCamp_KeyDown
And IS ONLY ADDED to the instance which I want it responds to. But some strange things happen like for example it raises with the last TextBox created dynamically.
Also I'm having problems like this while assigning properties or methods to distinguish them...
Is it possible to solve this? I tried Reflection but it didn't solve my problems, or I didn't realise in the good way...
Many thanks to all.
Zardoz
I am having a problem while trying to assign an event to a generated textbox control. This textbox is generated dynamically, its a variable which name is "txtCamp", for this variable I generate a certain number of instances in the layout screen in some differents positions, to have a binding to the database fields.These textboxes have a different property "Name" assigned dynamically to distinguish them. Then I add a new Event Handler which responds to the "KeyDown" event of the textbox. My problem comes when I want to distinguish between all the "KeyDown" Events of these instances of the variable "txtCamp". The code added to the "KeyDown" event is the typical one:
Private Sub txtCamp_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtCamp.KeyDown
txtCamp.BackColor = System.Drawing.Color.Gold
btModify.Enabled = False
btDelete.Enabled = False
End Sub
The event handlet is added normally like this:
AddHandler txtCamp.KeyDown, AddressOf txtCamp_KeyDown
And IS ONLY ADDED to the instance which I want it responds to. But some strange things happen like for example it raises with the last TextBox created dynamically.
Also I'm having problems like this while assigning properties or methods to distinguish them...
Is it possible to solve this? I tried Reflection but it didn't solve my problems, or I didn't realise in the good way...
Many thanks to all.
Zardoz