Delphi7中Listview的經常使用功效匯總。本站提示廣大學習愛好者:(Delphi7中Listview的經常使用功效匯總)文章只能為提供參考,不一定能成為您想要的結果。以下是Delphi7中Listview的經常使用功效匯總正文
有些時刻我們在應用Delphi7的Listview進程中老是要改一些默許的設置,如今把它們集中起來匯總以下。
MultiSelect := True; 使Listview可以同時選擇多行
GridLines := True; 使Listview顯示格線
ViewStyle := vsReport; 顯示數據項的具體列表
HideSelection := True; 使listview掉去核心時,選中行不高亮
//設置色彩 procedure TForm1.ListView1CustomDrawItem(Sender: TCustomListView; Item: TListItem; State: TCustomDrawState; var DefaultDraw: Boolean); var subRect, itemRect: TRect; i, SubItem: Integer; begin DefaultDraw := False; if Item.Selected then begin Sender.Canvas.Font.Color := clRed; //選中行字體色彩 Sender.Canvas.Brush.Color := clgray; //clGreen; 選中行高亮色彩 end else begin Sender.Canvas.Font.Color := clNavy; //正常行字體色彩 Sender.Canvas.Brush.Color := clWhite; //正常行高亮色彩 end; itemRect := Item.DisplayRect(drLabel); subRect := itemRect; for SubItem := 0 to (Sender as TListView).Columns.Count - 1 do begin subRect.Left := itemRect.Left; for i := 1 to SubItem do begin subRect.Left := subRect.Left + (Sender as TListView).Column[i - 1].Width; subRect.Right := subRect.Right + SubRect.Left + (Sender as TListView).Column[i].Width; end; if SubItem = 0 then begin subRect.Right := subRect.Right + 2; Sender.Canvas.TextRect(subRect, subRect.Left, subRect.Top, Item.Caption); end else Sender.Canvas.TextRect(subRect, subRect.Left, subRect.Top, Item.SubItems[SubItem - 1]); end; end;
//排序功效 private { Private declarations } SortCol: Integer; SortWay: Integer; procedure TForm1.ListView1ColumnClick(Sender: TObject; Column: TListColumn); begin SortCol := Column.Index; if (SortWay = 1) then SortWay := -1 else SortWay := 1; (Sender as TCustomListView).AlphaSort; end; procedure TForm1.ListView1Compare(Sender: TObject; Item1, Item2: TListItem; Data: Integer; var Compare: Integer); var t: Integer; begin if (SortCol = 0) then begin Compare := SortWay * CompareText(Item1.Caption, Item2.Caption); end else begin t := SortCol - 1; Compare := SortWay * CompareText(Item1.SubItems[t], Item2.SubItems[t]); end; end;
這個功效存在一個成績:數字排序會按字符相似排,例如:1,10,102,3,34,356......感興致的讀者可以加以完美