請教各位
我用DIR()找到了一堆檔案
然後要把這些檔案
Do While ......
.......
ListBox1.AddItem ans
.....
然後我有將ListBox1的Sorted=Ture
它會由小排到大
那麼,如果我想由大排到小呢,我要怎麼設呢,謝謝各位
我用DIR()找到了一堆檔案
然後要把這些檔案
Do While ......
.......
ListBox1.AddItem ans
.....
然後我有將ListBox1的Sorted=Ture
它會由小排到大
那麼,如果我想由大排到小呢,我要怎麼設呢,謝謝各位
文章標籤
全站熱搜

可以試試ListView,可以很容易的解決你的問題 ListBox,我想不自己寫點程式可能是真的有點小難吧
請善用google網上論壇(http://www.google.com.tw/grphp?q=&ie=UTF-8&oe=UTF-8&hl=zh-TW),關鍵字 listbox "sort order" 搜尋結果"How to use this ListBox sort routine?"有範例可以下載
先將sorted的屬性設為False 參考以下副程式 以下是由大到小排序數字,如果不是數字,就自己動動腦囉~~ Dim x() As Integer Dim i As Integer, j As Integer ReDim x(List1.ListCount - 1) For i = 0 To List1.ListCount - 1 x(i) = List1.List(i) Next i List1.Clear List1.AddItem x(0) For i = LBound(x) + 1 To UBound(x) For j = 0 To List1.ListCount - 1 If Val(List1.List(j)) < x(i) Then List1.AddItem x(i), j Exit For End If If j = List1.ListCount - 1 Then List1.AddItem x(i) End If Next j Next i
還是Sort的程式碼比較簡潔,我找到的範例實在是太難了 "How to use this ListBox sort routine?" http://groups.google.com.tw/groups?hl=zh-TW&lr=&ie=UTF-8&oe=UTF-8&th=965c4012aec4c189&rnum=1 "ListView Column Sorting (Advanced)" http://www.freevbcode.com/ShowCode.Asp?ID=484
一個更簡單的方法: 再放一個listbox同樣把sort打開,把資料丟進去 從最後面一個個放回要顯示的listbox(把sort關閉)裏就好了!
Excellent!!!
剛才找到的提供各位參考 "HOWTO: Sort a ListView Control by Date"http://support.microsoft.com/support/kb/articles/Q170/8/84.asp
提供一個最簡單的方法: (LIST1.SORTED設為TRUE) Dim i As Integer, tmpS As String List1.AddItem "5" List1.AddItem "1" List1.AddItem "4" List1.AddItem "3" List1.AddItem "2" For i = 0 To List1.ListCount - 1 tmpS = List1.List(List1.ListCount - 1) List1.RemoveItem List1.ListCount - 1 List1.AddItem tmpS, i Next 這樣就會降冪排列了! 再執行一次FOR...NEXT又變回昇冪排列!