How do I get the index of a control in a control array when that control is clicked?

06-16-2006, 09:16 AM
I have two control arrays (label and led). I need to get the index of the led when I click on one so I know what action to perform. How is this possible?

This is my event handler:

Public Sub TCLedClickEvent(ByVal sender As Object, ByVal e As EventArgs)
Dim TCLed As Led = DirectCast(sender, Led)
TCLed.Value = True
End Sub


06-16-2006, 12:56 PM
You should be able to use the IndexOf method from either the Array or ArrayLIst to detemine the position.

myIndex = MyCtrlArray.IndexOf(sender)

06-16-2006, 02:31 PM
This does not work:

BrokenTC(TCLeds.IndexOf(sender) + FirstBedTemp) = True

It doesn't like your indexof procedure although it picks it up using Intellisense.

06-19-2006, 11:32 AM
ahhh Array.IndexOf(TCLeds, sender) should work...

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum