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
ClayB [Syncfusion] - 30 Jun 2004 12:47 GMT
You might try code like:
Private Sub txtCamp_KeyDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyEventArgs) Handles txtCamp.KeyDown
Dim tb As TextBox = CType(sender, TextBox)
tb.BackColor = System.Drawing.Color.Gold
btModify.Enabled = False
btDelete.Enabled = False
End Sub
======================
Clay Burch, .NET MVP
Visit www.syncfusion.com for the coolest tools
> 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
>
[quoted text clipped - 8 lines]
>
> 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...
>
[quoted text clipped - 3 lines]
>
> Zardoz
Herfried K. Wagner [MVP] - 30 Jun 2004 13:05 GMT
* =?Utf-8?B?WmFyZG96?= <Zardoz@discussions.microsoft.com> scripsit:
> Private Sub txtCamp_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtCamp.KeyDown
>
[quoted text clipped - 10 lines]
> some strange things happen like for example it raises with the last
> TextBox created dynamically.
Post the code you use to create the new instances of the 'TextBox' class.

Signature
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/