我现在做的一个程序,是将数据表中的内容放到ListView中显示(VsReport),比较容易实现,我将其中一个时间字段的值放到ListBox中,然后根据ListBox中点选的值,在ListView中寻找,根据我所查找的资料是用FindData方法,但是没有效果啊,然后将OwnetData设为True,ListView就没有显示了,我真的没办法,怎样才能根据字符串值在ListView中查找到,请给出实例!!!!!
调试欢乐多
for i:=0 to ListView1.Count-1 do
begin
if ListView1.Items[i].SubItems[1]='你的时间' then
begin
ListView1.ItemIndex := i;
Break;
end;
end;
即使使用Virtual方式,几百万条数据也是需要至少分钟级别的耗时的,你又是如何加载的呢?
建立记录结构,
建立记录指针,
定义TList类型的指针列表变量,
遍历记录集生成新的纪录指针类型数据,加入到TList,
然后再ListView的OnData事件中加载数据!
begin
if ListView1.Items[i].SubItems[1]='你的时间' then
begin
ListView1.ItemIndex := i;
ListView1.TopItem := ListView1.Items[i];
Break;
end;
end;
==============================================================unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls;type
TForm1 = class(TForm)
ListView1: TListView;
Edit1: TEdit;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
var
i: Integer;
Item: TListItem;
begin
with ListView1 do
begin
Items.BeginUpdate;
for i:=1 to 1000 do
begin
Item := Items.Add;
Item.Caption := Format('%d', [i]);
end;
Items.EndUpdate;
end;
end;procedure TForm1.Button1Click(Sender: TObject);
var
i, idx: Integer;
begin
idx := ListView1.TopItem.Index;
ListView1.Scroll(0, -18 * idx);
for i:=0 to ListView1.Items.Count-1 do
begin
if Trim(ListView1.Items[i].Caption) = (Edit1.Text) then
begin
ListView1.ItemIndex := i;
Break;
end;
ListView1.Scroll(0, 18);
end;
end;end.
有意者请至电:021 6249 2931
[email protected]对不起打扰了! 实在要人要的急,楼主多包涵
请看看。谢谢!