执行搜索时,TListview未正确重新加载,清除搜索,然后重新加载列表视图。使用XE5。
步骤是:
对这个奇怪的事情有任何帮助???
代码如下:
procedure TForm1.FormCreate(Sender: TObject);
var
i: integer;
LItem: TListviewItem;
begin
if Assigned(Listview1) then
Listview1.Items.Clear;
for i := 1 to 20 do
begin
LItem := Listview1.Items.Add;
LItem.Text := IntToStr(i);
end;
end;
procedure TForm1.btnButton1Click(Sender: TObject); { reload button }
var
i: integer;
LItem: TListviewItem;
begin
btnButton2Click(btnButton2); <<<<edit add
if Assigned(Listview1.Items.Filter) then <<<<edit add
Listview1.Items.Filter := nil; <<<<edit add
if Assigned(Listview1) then
Listview1.Items.Clear;
for i := 1 to 20 do
begin
LItem := Listview1.Items.Add;
LItem.Text := IntToStr(i);
end;
end;
procedure TForm1.btnButton2Click(Sender: TObject); { clear button }
var
i: integer;
SearchBox: TSearchBox;
begin
for i := 0 to Listview1.Controls.Count - 1 do
if Listview1.Controls[i].ClassType = TSearchBox then
begin
SearchBox := TSearchBox(Listview1.Controls[i]);
Break;
end;
if Assigned(SearchBox) then
SearchBox.Text := '';
end;