·ListView是vsReport的排列方式~
//ListView.ViewStyle := vsReport;
·点击Column的时候,实现此列排序,在点又反着排序。
function CustSortAsc(Item1, Item2: TListItem;
ColIndex: Integer): Integer; stdcall;
var
Item1Str: string;
Item2Str: string;
// TmpExt: Extended;
begin
Result := 0;
Item1Str := '';
Item2Str := '';
if ColIndex < 0 then
Exit;
if ColIndex = 0 then
begin
Item1Str := Item1.Caption;
Item2Str := Item2.Caption;
end
else
begin
if ColIndex <= Item1.SubItems.Count then
Item1Str := Item1.SubItems[ColIndex - 1];
if ColIndex <= Item2.SubItems.Count then
Item2Str := Item2.SubItems[ColIndex - 1];
end;
{if ColIndex = 1 then //此列是自定义格式字符串,用UnFormatSize函数格式化后比较
Result := UnFormatSize(Item1Str) - UnFormatSize(Item2Str)
else if ColIndex = 5 then //此列是日期,故转成时间再比较
begin
TmpExt := StrToDateTime(Item1Str) - StrToDateTime(Item2Str);
if TmpExt > 0 then
Result := 1
else if TmpExt < 0 then
Result := -1
else
Result := 0;
end
else } //默认值是文本比较
Result := CompareText(Item1Str, Item2Str);
if (Result > 0) and (Item2Str = '') then
Result := -1
else if (Result < 0) and (Item1Str = '') then
Result := 1;
end;
function CustSortDesc(Item1, Item2: TListItem;
ColIndex: Integer): Integer; stdcall;
begin
Result := CustSortAsc(Item1, Item2, ColIndex);
Result := Result * -1;
end;
procedure TForm1.ListView1ColumnClick(Sender: TObject;
Column: TListColumn);
begin
if Column.ImageIndex = 1 then
begin
ListView1.CustomSort(@CustSortDesc, Column.Index);
Column.ImageIndex := 2;
end
else
begin
ListView1.CustomSort(@CustSortAsc, Column.Index);
Column.ImageIndex := 1;
end;
end;
·像QQ里查询好友的界面一样,最好在加上格格。
//ListView1.GridLines := True;
·最好还有字体不同颜色的显示
// ???
·分数不多了,谢谢回答
·签名:美女雪儿
//[
][
][
]