From: Massimo Riccardi on
Hi all,

I have an array of controls (made at runtime) and containing 10 buttons
(Button(0),Button(1)....etc.).
Ho I can get the index of a selected control?
For example if I click the button number 5 how I can retrieve its index
(that it is the fifth button)?
(In VB6 there was the "INDEX" .....)

Thanks
Massimo


From: Family Tree Mike on
On 12/20/2009 9:02 AM, Massimo Riccardi wrote:
> Hi all,
>
> I have an array of controls (made at runtime) and containing 10 buttons
> (Button(0),Button(1)....etc.).
> Ho I can get the index of a selected control?
> For example if I click the button number 5 how I can retrieve its index
> (that it is the fifth button)?
> (In VB6 there was the "INDEX" .....)
>
> Thanks
> Massimo
>
>

In your click handler:
Dim b as Button = CType(sender, Button)
dim idx as integer = Array.IndexOf(Button, b)

--
Mike
From: eBob.com on
Most straightforward would be to simply do a lookup. More efficient would
be to take advantage of the Button's Tag property. I.E. simply set the Tag
to the index value.

Bob

"Massimo Riccardi" <rimassimo(a)aliceposta.it> wrote in message
news:4b2e2e6d$0$1106$4fafbaef(a)reader3.news.tin.it...
> Hi all,
>
> I have an array of controls (made at runtime) and containing 10 buttons
> (Button(0),Button(1)....etc.).
> Ho I can get the index of a selected control?
> For example if I click the button number 5 how I can retrieve its index
> (that it is the fifth button)?
> (In VB6 there was the "INDEX" .....)
>
> Thanks
> Massimo
>


From: Phill W. on
Massimo Riccardi wrote:

> I have an array of controls (made at runtime) and containing 10 buttons
> (Button(0),Button(1)....etc.).
> How I can get the index of a selected control?

Why do you need it?

Event handlers all receive a reference to the Control that raised the
event, so you don't need to index for that ...

Private Sub AnyButton_Click( _
byval sender as Object _
, byval e as EventArgs _
)
Dim btn as Button = Nothing
If TypeOf sender is Button Then
btn = DirectCast( sender, button )
End If

btn.Text = ...

End Sub

HTH,
Phill W.