0
以下代码位将根据TEdit
控件中输入的内容筛选TListView
控件的项目,并且如果ListView由单个列组成,且列中多于1列然而,当应用过滤器时,其他列中的项会被销毁,所以我希望有人可能知道需要添加到下面的代码中以在ListView被过滤时保留这些列。筛选多列列表视图
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, strutils, StdCtrls, ComCtrls;
type
TForm1 = class(TForm)
ListView1: TListView;
Edit1: TEdit;
procedure Edit1Change(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
StrList : TStringList;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
Index : Integer;
begin
StrList := TStringList.Create;
for Index := 0 to ListView1.Items.Count -1 do
StrList.Add(ListView1.Items[Index].Caption);
end;
procedure TForm1.Edit1Change(Sender: TObject);
var
Index : Integer;
begin
ListView1.Clear;
for Index := 0 to StrList.Count - 1 do
if Pos(Edit1.Text, StrList.Strings[Index]) > 0 then
ListView1.AddItem(StrList.Strings[Index], nil);
if Edit1.Text = '' then
for Index := 0 to StrList.Count - 1 do
ListView1.AddItem(StrList.Strings[Index], nil);
end;
end.
不听起来像是要一排过滤器显然是包含或排除的行。看起来很喜欢你想在单元格中粘贴一个空白值,如果它不匹配。如果没有任何列匹配,也许不要添加行... – 2012-07-28 14:34:43
或者你也许可以测试每一列,并且如果它们中的任何一列匹配添加该行,他在经过一段时间的思考后说。更好的是,你将行中的数据和过滤器传递给一个布尔函数,并且如果是true,那么将是更自然的方法。 – 2012-07-28 14:37:59
对不起,我不太理解你的回答。你会再试一次吗?感谢您的答复btw。我所要做的就是创建一个像DBgrid一样的过滤器,但不是使用Dataset的网格,而是简单地使用ListView和编辑控件。 – avue 2012-07-28 14:38:35