Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

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:

 

Private vKey As New List(Of Button)

 

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

 

   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!

Edited by Doggo120
  • Leaders
Posted

Re: How to sort List of Buttons

 

The Sort method comes in handy:

   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

[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...