Re: Get button name on click
Code:
Private Sub DynamicButton_Click(ByVal sender As Object, e As MouseEventArgs)
For Each cntrl In Me.Controls
If TypeOf cntrl Is Button Then
Dim btn As Button = DirectCast(cntrl, Button)
'''>>> Getting name is always wrong (btn.name)
Exit Sub
End If
Next
End Sub
You want the name of the button clicked? Then why arent' you looking at the sender object? that's the thing that was clicked...
Code:
Private Sub DynamicButton_Click(ByVal sender As Object, e As MouseEventArgs)
MessageBox.Show(DirectCast(sender, Button).Name)
End Sub
your code is currently looping through all the controls on the form, finding the first button it comes to and giving you the name of THAT button... not the one clicked...
-tg
Re: Get button name on click
techgnome..... thank you, that did what I needed. I knew I was doing something stupid there. Thanks a bunch!