Pergunta

I created a Sub I want to run everytime one of two buttons is clicked. I added the handles of both buttons to the sub so that clicking either one will fire the subroutine.

I placed listview object A in buttonA.tag, and listview object B in buttonB.

When the button is clicked I do my best to extract the listview instance tucked into the button's tag. The problem is there is no instance in the tag. It is simply "nothing."

Private Sub Execute(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnA.Click, btnB.Click

        Dim buttonSender As Button = Nothing

        buttonSender = CType(sender, Button)

        Dim btnListView As ListView = buttonSender.Tag

    End Sub

-------------------Edit-1

Private Sub Form_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.btnA.Tag = Me.lvA
        Me.btnB.Tag = Me.lvB
    End Sub

Your time is appreciated.

Foi útil?

Solução

Try this,

Dim buttonSender As Button = CType(sender, Button)
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top