Natural Sort アルゴリズムを使用する CheckedListboxes を作成するために、次のクラスを作成しました。ただし、オーバーライドされたSort()
メソッドは起動されません。
(そのメソッド内のコードは、通常のリストボックスに独自の並べ替えアルゴリズムを実装する方法に関する MSDN の例からのものです。)
Public Class NaturalSortedCheckedListbox
Inherits CheckedListBox
Private _naturalComparer As New NaturalSortComparer
Public Sub New()
MyBase.new()
End Sub
Protected Overrides Sub Sort()
'** A breakpoint on the following line will not get hit.
If Items.Count > 1 Then
Dim swapped As Boolean
Do
Dim counter As Integer = Items.Count - 1
swapped = False
While counter > 0
If _naturalComparer.Compare(Items(counter).ToString(), Items(counter - 1).ToString()) = -1 Then
Dim temp As Object = Items(counter)
Items(counter) = Items(counter - 1)
Items(counter - 1) = temp
swapped = True
End If
counter -= 1
End While
Loop While swapped
End If
End Sub
End Class
CheckedListbox は Listbox から派生しているため、Sort()
オーバーライドが機能すると考えましたが、なぜ機能しないのかがわかりません。
インスタンスの を設定しています.Sorted = True
が、それはデフォルトのアルゴリズムを使用してアイテムを並べ替えているだけであり、Natural Sort アルゴリズム (他の場所でテストされ、期待どおりに動作することが示されています) ではありません。