delphi刚入道,请教如何往ListView中添加信息? 最好给个例子?马上给分!
解决方案 »
- Dll窗体继承的问题
- 如何取得excelworksheet的打印总页数?
- 怎样对dbgrid中的数据记录实现具体定位?
- 如何在一个非主窗口最小化前执行一段代码
- delphi做的tcp程序在没有装delphi的机子上要qtintf70.dll,可这个文件有3m多,编译的时候怎么集成缩小啊?
- 求购 Delphi进销存程式设计和Delphi5企业级解决方案及应用剖析
- 关于发邮件的问题
- 求用 API 播放 AVI 的源码 ,谢谢(win32 application 工程下播放)
- WriteLn(MyText,'['+ThisItem+']')写文本时出错?
- 有人用delphi开发过APP不?
- 在delphi环境下,SQL语句超过255个字节,如何解决?
- 如何获取Tedit编辑框获得焦点时,当前光标的位置
Names: array[0..5, 0..1] of string = (
('Rubble', 'Barney'),
('Michael', 'Johnson'),
('Bunny', 'Bugs'),
('Silver', 'HiHo'),
('Simpson', 'Bart'),
('Squirrel', 'Rocky')
);var
I: Integer;
NewColumn: TListColumn;
ListItem: TListItem;
ListView: TListView;
begin
ListView := TListView.Create(Self);
with ListView do
begin
Parent := Self;
Align := alClient; ViewStyle := vsReport; NewColumn := Columns.Add;
NewColumn.Caption := 'Last';
NewColumn := Columns.Add;
NewColumn.Caption := 'First'; for I := Low(Names) to High(Names) do
begin
ListItem := Items.Add;
ListItem.Caption := Names[I][0];
ListItem.SubItems.Add(Names[I][1]);
end;
end;
end;
procedure NewItem(obj:tObject;ID:Integer;code:String;Image:Integer):tListItem;
Var
Itemx:tListItem;
Pdata:Pinteger;
begin
Itemx:=obj.items.add;
Itemx.caption:=code;
Itemx.Imagelist:=Image; New(Pdata);
Pdata^:=ID;
Itemx.data:=Pdata;
result:=Itemx;
end;procedure InsertValues(ID:Integer;code,name:String);
var
Item:tListItem;
begin
Item:=NewItem(ListView1,ID,code,1);
Item.subitems.add(name);
end;调用:
InsertValues(adoquery.fieldvalues['id'],adoquery.fieldvalues,['code'],adoquery.fieldvalues['name']);
试一下,没有调试
var
schSql:string;
schQry:TADOQuery;
begin
schSql:='Select * from view_all_product where 1=1';
if trim(edit_Lowprice.Text)<>'' then //成交价下区间不为空
schSql:=schSql+'and bargain_price>='+(trim(edit_LowPrice.Text));
if trim(edit_HighPrice.Text)<>'' then //成交价上区间不为空
schSql:=schSql+' and bargain_price<='+trim(edit_HighPrice.Text); if cmb_FirCatalog.ItemIndex > 0 then //一级目录不为空
begin
if cmb_SecCatalog.ItemIndex > 0 then //二级目录不为空
begin
if cmb_ThiCatalog.ItemIndex > 0 then //三级目录不为空
schSql:=schSql+' and third_name='''+trim(cmb_ThiCatalog.Text)+''' and first_name='''+trim(cmb_FirCatalog.Text)+''' and second_name='''+trim(cmb_SecCatalog.Text)+''''
else
schSql:=schSql+' and second_name='''+trim(cmb_SecCatalog.Text)+''' and first_name='''+trim(cmb_FirCatalog.Text)+'''';
end
else
schSql:=schSql+' and first_name='''+trim(cmb_FirCatalog.Text)+'''';
end; if cmb_ComName.ItemIndex > 0 then //拍卖公司不为空
schSql:=schSql+' and companyname='''+trim(cmb_ComName.Text)+'''';
if trim(edit_Author.Text)<>'' then //作者不为空
schSql:=schSql+' and product_author like''%'+trim(edit_Author.Text)+'%'''; if trim(edit_GoodNum.Text)<>'' then //拍品序号不为空
schSql:=schSql+' and product_code like'''+trim(edit_GoodNum.Text)+'%''';
if trim(edit_GoodName.Text)<>'' then //拍品名称不为空
schSql:=schSql+' and product_name like''%'+trim(edit_GoodName.Text)+'%'''; schSql:=schSql+' order by bargain_price desc,companyname';
ListView_Topten.Show;
ListView_Topten.Items.Clear;
try
schQry:=TADOQuery.Create(self);
schQry.ConnectionString:=DBLink;
schQry.SQL.Clear;
schQry.SQL.Add(schSql);
schQry.Open;
schQry.First;
while not schQry.Eof do
begin
With ListView_Topten.Items.Add do
begin
Caption := schQry.FieldByName('product_code').AsString; //拍品序号
SubItems.Add(schQry.FieldByName('product_name').AsString); //拍品名称
SubItems.Add(schQry.FieldByName('product_years').AsString); //年代
SubItems.Add(schQry.FieldByName('product_size').AsString); //尺寸
SubItems.Add(schQry.FieldByName('product_author').AsString); //作者
SubItems.Add(schQry.FieldByName('bargain_moneycode').AsString); //成交货币类型
SubItems.Add(schQry.FieldByName('bargain_price').AsString); //成交价
SubItems.Add(schQry.FieldByName('bargain_date').AsString); //成交时间
SubItems.Add(schQry.FieldByName('companyname').AsString); //拍卖公司
end;
schQry.Next;
end;
schQry.Close;
schQry.Free;
except
MessageDlg('查询失败',mtError,[mbok],0);
end;
end;
最近也在写向listview中添加数据,凑合这样吧