Delphi listview 点击列头排序
2016-11-05 00:45
579 查看
listview 的数字排序。
首先添加全局变量m_bSort: Boolean = false;//控制双向排序 function CustomSortProc(Item1, Item2: TListItem; ParamSort: Integer): Integer;stdcall;
之后在需要排序的listview 控件的OnColumClick 事件中编写代码
procedure TMainForm.lv_UpLoadListColumnClick(Sender: TObject; Column: TListColumn); begin if (Column.Index = 1) or (Column.Index = 3) then begin lv_UpLoadList.CustomSort(@CustomSortProc, Column.Index); m_bSort := not m_bSort; end; end;
之后编写全局函数
function CustomSortProc(Item1, Item2: TListItem; ParamSort: Integer): Integer; stdcall; var // txt1, txt2: string; txt1, txt2: Integer; begin if ParamSort <> 0 then begin try txt1 := StrToInt(Item1.SubItems.Strings[ParamSort - 1]); txt2 := StrToInt(Item2.SubItems.Strings[ParamSort - 1]); if m_bSort then begin // Result := CompareText(txt1, txt2); Result := txt1 - txt2; end else begin Result := -(txt1 - txt2); // Result := -CompareText(txt1, txt2); end; except end; end else begin if m_bSort then begin Result := CompareText(Item1.Caption, Item2.Caption); end else begin Result := -CompareText(Item1.Caption, Item2.Caption); end; end; end;
以上是数字的排序,如果需要汉字什么的排序,这将上面的strtoint去掉,并将上面的注释行替换上面的行就行了
相关文章推荐
- Delphi ListView排序
- listView的增删,行单击事件,头部点击排序等功能
- ListView点击列头排序
- 在C#中实现对ListView点击列标题自动排序功能
- 在C#中实现对ListView点击列标题自动排序功能
- listview控件实现点击列表头进行listview排序示例分享
- 公司要求开发一个继承System.Windows.Forms.ListView类的组件,要求达到以下的特殊功能:点击ListView各列列头时,能按照点击列的每行值进行重排视图中的所有行 (排序的方式如DataGrid相似)。根据您的知识,
- 对ListView点击列标题自动排序功能
- Delphi的ListView自动排序
- Android ListView A-Z侧边栏字母排序,点击处扭曲成半圆
- Delphi的ListView自动排序
- 在C#中实现对ListView点击列标题自动排序功能
- Delphi ListView排序
- Listview中实现点击栏目标题排序
- C#:ListView控件如何实现点击列表头进行排序
- C# ListView 点击标题头排序(二分法排序)(泛型)
- Delphi ListView排序
- [WPF]ListView点击列头排序功能实现
- 在C#中实现对ListView点击列标题自动排序功能
- 为ListView添加自动列宽调整和点击列表头自动排序功能