none
AddHandler: refer to dynamically created object in the Handler RRS feed

  • Question

  • All

    I have a RibbonDropDownList which I created dynamically and to which I added a Handler

    AddHandler rbZebrix.SelectionChanged, AddressOf cboZebrix_TextChanged

     Public Sub cboZebrix_TextChanged()
     msgbox("You changed the value in the DropDownList")
    end sub

    This works as expected. When I run the program and I select another value in the dropdownlist, the messagebox does appear.

    I also want to show the selected value in the msgbox. It thought this would be simple by changing the AddHanlder and the code into

    AddHandler rbZebrix.SelectionChanged, AddressOf cboZebrix_TextChanged(rbZebrix)

     Public Sub cboZebrix_TextChanged(rb as RibbonDropDown)
     msgbox("You changed the value in the DropDownList to: " & rb.ToString)
    end sub

    However, this ends op in the error "AddressOf" operand must be the name of a method (without parentheses)

    So how can I solve this?

    Regards
    Ino

    Monday, March 30, 2020 1:39 PM

Answers

  • TextChanged parameters are "sender As Object, e As EventArgs", any control which has an event predefined will have predefined parameters.

    sender is always the object that invoked the event so if you then know sender is a TextBox we can use

    CType(sender,TextBox)

    So the message is valid that no parameters may be passed.

    When looking at RibbonDropDown.SelectionChanged event in this event you can ask question on Selecteditem or SelectedItemIndex.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by ino_mart Tuesday, March 31, 2020 10:29 AM
    Monday, March 30, 2020 2:14 PM
    Moderator
  • Karen

    Thanks.  That solved my issue.  For the others who are also struggling with this, hereby my adjusted code

    AddHandler rbZebrix.SelectionChanged, AddressOf rbZebrix_SelectionChanged

     Public Sub rbZebrix_SelectionChanged(ByVal sender As Object, ByVal e As EventArgs)
       MsgBox(sender.selecteditem.ToString)
    End Sub

    • Marked as answer by ino_mart Tuesday, March 31, 2020 10:29 AM
    Tuesday, March 31, 2020 10:28 AM

All replies

  • TextChanged parameters are "sender As Object, e As EventArgs", any control which has an event predefined will have predefined parameters.

    sender is always the object that invoked the event so if you then know sender is a TextBox we can use

    CType(sender,TextBox)

    So the message is valid that no parameters may be passed.

    When looking at RibbonDropDown.SelectionChanged event in this event you can ask question on Selecteditem or SelectedItemIndex.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by ino_mart Tuesday, March 31, 2020 10:29 AM
    Monday, March 30, 2020 2:14 PM
    Moderator
  • Karen

    Thanks.  That solved my issue.  For the others who are also struggling with this, hereby my adjusted code

    AddHandler rbZebrix.SelectionChanged, AddressOf rbZebrix_SelectionChanged

     Public Sub rbZebrix_SelectionChanged(ByVal sender As Object, ByVal e As EventArgs)
       MsgBox(sender.selecteditem.ToString)
    End Sub

    • Marked as answer by ino_mart Tuesday, March 31, 2020 10:29 AM
    Tuesday, March 31, 2020 10:28 AM