I have a screen with an array of labels (coded as: label[] aLabel = new label[30];
I would like to write a single DoubleClick event that handles all Double Click events for the array but action taken would be unique for the aLabel[] clicked. Therefore I have to determine which aLabel was DoubleClicked - there in lies the problem. There seems to be no way of determining the index value of the aLabel initiating the event. the sender data (in the event handler) can be viewed when in debug mode in VS2008 but there is no way of access this data withou knowning which indexed aLabel was clicked.
Any ideas??? this is driving me crazy and I'd hate to have to create 31 event handles, one for each indexed aLabel.
Loading
Sam HobbsPosted Apr 1, 2010, 12:41 PM
Ramon LiverancePosted Apr 1, 2010, 8:45 AM
Thanks again.
Sam HobbsPosted Mar 30, 2010, 11:18 PM
Then l.Tag is the Tag.
Ramon LiverancePosted Mar 30, 2010, 7:55 PM
How would you read the tag property without first knowing the index? I'm somewhat new to this piece of C# so any additional info to ease the pain would be great. The problem I had with reading ANYTHING from within the event handler (that builtin DoubleClick handler) is that I first needed to know the fully qualified control name, including the index#. Once determined then of course I could read the tag with a simple 'aLabel[index].tag' but without the index I was toast. I really couldn't seem to find any alternative to the compare with the sender...
Sam HobbsPosted Mar 30, 2010, 6:46 PM
Even better, just set the label's Tag property to something, such as the array index. The Tag property can be any object; it could be an instance of a class with much more data.
Ramon LiverancePosted Mar 30, 2010, 5:39 PM
if (sender == aLabel[0]) {int arrayIndex = 0;]
if (sender == aLabel[1]) {int arrayIndex = 1;}
Of course you could use a SWITCH/CASE statement, a FOR Loop etc. as well. As luck would have it I spent the better part of a day looking for the answer and testing various ideas only to stumble on the answer as soon as I put the question up on the Forum here. Sorry! :-)