首先添加全局變量函數
m_bSort: Boolean = false; CustomSortProc(Item1, Item2: TListItem; ParamSort: Integer): Integer;;
以後在須要排序的listview 控件的OnColumClick 事件中編寫代碼spa
TMainForm.lv_UpLoadListColumnClick(Sender: TObject; Column: TListColumn); (Column. = 1) (Column. = 3) lv_UpLoadList.CustomSort(@CustomSortProc, Column.); m_bSort := m_bSort; ; ;
以後編寫全局函數code
CustomSortProc(Item1, Item2: TListItem; ParamSort: Integer): Integer; ; txt1, txt2: Integer; ParamSort <> 0 try txt1 := StrToInt(Item1.SubItems.Strings[ParamSort - 1]); txt2 := StrToInt(Item2.SubItems.Strings[ParamSort - 1]); m_bSort Result := txt1 - txt2; Result := -(txt1 - txt2); ; except ; m_bSort Result := CompareText(Item1.Caption, Item2.Caption); Result := -CompareText(Item1.Caption, Item2.Caption); ; ; ;
以上是數字的排序,若是須要漢字什麼的排序,這將上面的strtoint去掉,並將上面的註釋行替換上面的行就好了orm