我有一個ListView設置爲vsIcon。每個項目都是下面有一個小文本的圖像。當我添加很多項目時,它們被包裝爲ListView的寬度(例如,一行中的5個項目)。但是當我改變它的寬度時,它們不會再被新的寬度包裹。如何在Delphi中觸發ListView中項目的包裝?
我試過到目前爲止:
ListView.Update;
ListView.Refresh;
ListView.Repaint;
function ListView_Arrange(hwndLV:HWND; Code:UINT):Bool;
函數ListView_RedrawItems(hwndLV:HWND; iFirst,iLast:Integer):Bool;
我還沒有嘗試對項目進行排序,因爲我不希望它們被排序。但大多數情況下,他們排序如此排序沒有多大幫助(如果它會包裝它們,我不相信它會)。
我現在用的是什麼:
procedure TForm.WMExitSizeMove(var Message: TMessage);
var
i, p: Integer;
ListItem: TListItem;
c: array of string;
b: array of Boolean;
begin
if Showing and (PreviousWidth <> Width) then
begin
p := ListView.ItemIndex;
SetLength(c, ImageList.Count);
SetLength(b, ImageList.Count);
for i := 0 to ImageList.Count - 1 do
begin
c[i] := ListView.Items[i].Caption;
b[i] := ListView.Items[i].Selected;
end;
ListView.Items.BeginUpdate;
ListView.Clear;
for i := 0 to ImageList.Count - 1 do
begin
ListItem := ListView.Items.Add;
ListItem.Caption := c[i];
ListItem.ImageIndex := i;
ListItem.Selected := b[i];
end;
ListView.ItemIndex := p;
ListView.Items.EndUpdate;
SetLength(c, 0);
SetLength(b, 0);
PreviousWidth := Width;
end;
inherited;
end;
但是,當你看到,它不是快速的大量的物品。 你能幫我找個更好的方法嗎?
謝謝。
我使用Delphi 7.
謝謝,但它不工作。 – DavidB
我用一個ListView和一堆項目做了一個簡單的應用程序。我將ListView錨定到窗體並將AutoArrange設置爲true,並且所有內容都按預期工作。 你是否重寫了任何可能阻止默認繪製的繪圖事件? – DogLimbo
繪圖事件不是問題,但ShowWorkAreas屬性設置爲True。似乎在設置爲False時正在工作。誰知道......:D謝謝。 – DavidB