Using event handler - how to identify which control was clicked when several controls 'share' the same eventhandler?
-
I have created an 'grid' of text boxes 17 (rows) by 20 (columns) within a groupbox. This is like using a conrtol array in VB6. I gave each a unique name e.g. txtboxR08C12 (row 8 column 12) Just prior to adding the control to the group box I added an EventHandler to the textbox. How can I identify in the EventHandler exactly which of the textboxes (preferably by name). So that I can amend the background colour and the contents to reflect a count (determined elsewhere in my code and stored in an array)
-
I have created an 'grid' of text boxes 17 (rows) by 20 (columns) within a groupbox. This is like using a conrtol array in VB6. I gave each a unique name e.g. txtboxR08C12 (row 8 column 12) Just prior to adding the control to the group box I added an EventHandler to the textbox. How can I identify in the EventHandler exactly which of the textboxes (preferably by name). So that I can amend the background colour and the contents to reflect a count (determined elsewhere in my code and stored in an array)
-
I have created an 'grid' of text boxes 17 (rows) by 20 (columns) within a groupbox. This is like using a conrtol array in VB6. I gave each a unique name e.g. txtboxR08C12 (row 8 column 12) Just prior to adding the control to the group box I added an EventHandler to the textbox. How can I identify in the EventHandler exactly which of the textboxes (preferably by name). So that I can amend the background colour and the contents to reflect a count (determined elsewhere in my code and stored in an array)
-
dim x as textbox = ctype(sender,textbox) if x.name = "txtboxR08C12" .... (I think my vb syntax is correct)
Bob Ashfield Consultants Ltd
-
Thanks for your answer I mentioned vb6 as that is where I know control arrays from. But I was looking for a c# method. Thank you for your time
TextBox tb = sender as Textbox;
if (tb.Name == ...
-
I have created an 'grid' of text boxes 17 (rows) by 20 (columns) within a groupbox. This is like using a conrtol array in VB6. I gave each a unique name e.g. txtboxR08C12 (row 8 column 12) Just prior to adding the control to the group box I added an EventHandler to the textbox. How can I identify in the EventHandler exactly which of the textboxes (preferably by name). So that I can amend the background colour and the contents to reflect a count (determined elsewhere in my code and stored in an array)
TextBox box = sender as TextBox;
box will then become the textbox that has fired the event, and you can handle it accordingly.Mark Brock Click here to view my blog
-
Thanks for your answer I mentioned vb6 as that is where I know control arrays from. But I was looking for a c# method. Thank you for your time
-
TextBox box = sender as TextBox;
box will then become the textbox that has fired the event, and you can handle it accordingly.Mark Brock Click here to view my blog