none
Use buttonhandler for all comboboxes RRS feed

  • Question

  • Hello,

    I use this when i select an item in a Combox to avoid using the mouse wheel to change the collection in the Combobox

     Private Sub buttonHandler(ByVal sender As System.Object, ByVal e As System.EventArgs)
            Dim mwe As HandledMouseEventArgs = DirectCast(e, HandledMouseEventArgs)
            mwe.Handled = True
        End Sub
    
        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    
            AddHandler ComboBox1.MouseWheel, AddressOf buttonHandler
        End Sub

    That works fine , but i have to put AddHandler for every combobox in Formload.

    I have made something with Tabpage's en a lot of Combobox's

    What code do i have to put in Formload to adress AddHandler for all Comboboxes in the Tabpage's in the Form1 ?

    Saturday, June 9, 2018 5:26 PM

Answers

  • That is fine or an alternate

    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Controls.OfType(Of Control).ToList.ForEach(
                Sub(cb)
                    If TypeOf cb Is ComboBox Then
                        AddHandler cb.MouseWheel,
                            Sub(s As System.Object, a As EventArgs)
                                Dim mwe As HandledMouseEventArgs = DirectCast(a, HandledMouseEventArgs)
                                mwe.Handled = True
                            End Sub
                    End If
                End Sub)
        End Sub
    End Class
    


    Please remember to mark the replies as answers if they help and unmark 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.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by KeesBlunder Sunday, June 10, 2018 5:09 AM
    Saturday, June 9, 2018 7:09 PM
    Moderator

All replies

  • This is working , is this a correct way ?

      For Each c As Control In Me.Controls.OfType(Of ComboBox)()
                'You cann acces to ComboBox her by c
                AddHandler c.MouseWheel, AddressOf buttonHandler
            Next

    Saturday, June 9, 2018 5:35 PM
  • That is fine or an alternate

    Public Class Form1
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Controls.OfType(Of Control).ToList.ForEach(
                Sub(cb)
                    If TypeOf cb Is ComboBox Then
                        AddHandler cb.MouseWheel,
                            Sub(s As System.Object, a As EventArgs)
                                Dim mwe As HandledMouseEventArgs = DirectCast(a, HandledMouseEventArgs)
                                mwe.Handled = True
                            End Sub
                    End If
                End Sub)
        End Sub
    End Class
    


    Please remember to mark the replies as answers if they help and unmark 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.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by KeesBlunder Sunday, June 10, 2018 5:09 AM
    Saturday, June 9, 2018 7:09 PM
    Moderator
  • Thanks
    Sunday, June 10, 2018 5:09 AM