How to arrange List of Buttons

Doggo120

Newcomer
Joined
Oct 7, 2011
Messages
23
Location
Colombia
How to sort List of Buttons

Hey beautiful people!

I'm working on a User Control, and I've created a List variable like this:

Code:
Private vKey As New List(Of Button)

Then I search for all the buttons in the user control and add them:

Code:
    Private Sub AddToList()
        For Each Key As Control In Me.Controls
            If TypeOf (Key) Is Button Then
                vKey.Add(Key)
            End If
        Next
    End Sub

I'd want to sort the list by the button names ('cause they're added in some unknown order)

Thanks!
 
Last edited:
Re: How to sort List of Buttons

The Sort method comes in handy:
Code:
    Sub SortButtons()
        vKey.Sort(AddressOf SomeButtonCompareFunction)
    End Sub

    Function SomeButtonCompareFunction(ByVal A As Button, ByVal B As Button) As Integer
        ' You probably want to perform a string compare of the two button's names here.
    End Function
 
Back
Top