Guest User

How to sort items in ToolStripItemCollection

a guest
Mar 23rd, 2012
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. Dim onClickHandler As System.EventHandler = New System.EventHandler(AddressOf Symbol_Click)
  2. Dim item As New ToolStripMenuItem(newSymbol, Nothing, onClickHandler)
  3. SomeToolStripMenuItem.DropDownItems.Add(item)
  4.  
  5. Private Sub ResortToolStripItemCollection(coll As ToolStripItemCollection)
  6. Dim oAList As New System.Collections.ArrayList(coll)
  7. oAList.Sort(new ToolStripItemComparer())
  8. coll.Clear()
  9.  
  10. For Each oItem As ToolStripItem In oAList
  11. coll.Add(oItem)
  12. Next
  13. End Sub
  14.  
  15. Private Class ToolStripItemComparer Implements System.Collections.IComparer
  16. Public Function Compare(x As Object, y As Object) As Integer Implements System.Collections.IComparer.Compare
  17. Dim oItem1 As ToolStripItem = DirectCast(x, ToolStripItem)
  18. Dim oItem2 As ToolStripItem = DirectCast(y, ToolStripItem)
  19. Return String.Compare(oItem1.Text,oItem2.Text,True)
  20. End Function
  21. End Class
Advertisement
Add Comment
Please, Sign In to add comment