Delphi listview寫入時如何讓它自動返回頂部(第一行)
阿新 • • 發佈:2020-12-12
Delphi 中,讓 ListView 控制元件寫入時它自動返回頂部,可以參考以下程式碼:bai
procedureTForm1.Button1Click(Sender:TObject); var i:integer; ListItem:TListItem; begin fori:=1to1000do begin withListView1do begin ListItem:=Items.Add; ListItem.Caption:=Format('檔名稱%.4d',[i]); ListItem.SubItems.Add(Format('%.4d',[i])); end; end; end; procedureTForm1.Button2Click(Sender:TObject); begin ListView1.Selected:=ListView1.Items[0];//設定第1行為選中狀態 ListView1.Selected.MakeVisible(True);//重新整理讓第1行顯示 end;
執行程式碼截圖: