小弟想用listView实现这样一个功能,查询一个表(例如查询编号),然后把查询出来的编号写入listview,并且载入一个图标,
实现的效果是,一行中图标在上面,下面是编号,一行有五个图标,五个编号,不知道我说明白没..载入的图标可以是一样的请会的高人指点一下,关键是怎么操作listview,请用源码指示....
实现的效果是,一行中图标在上面,下面是编号,一行有五个图标,五个编号,不知道我说明白没..载入的图标可以是一样的请会的高人指点一下,关键是怎么操作listview,请用源码指示....
自己看看吧,比较详细
..\Borland\Delphi7\Demos下有listview的使用例子
2.设置listview的LargeImages为刚才的imagelist1控件
3.设置listview的viewStyle属性为vsIcon
4.增加一个项目的例子如下
procedure TForm1.Button1Click(Sender: TObject);
var
item:TListitem;
begin
item:=ListView1.Items.Add;
item.Caption:='编号'; //编号
item.ImageIndex:=1;//图标在imagelist的索引值
end;
procedure TForm1.InitListView;
var
bytI:byte;
sngWidth:single;
begin
try
with ListView1 do
begin
for bytI:=1 to 6 do
begin
Columns.Add;
end;
Columns[0].Caption:='11';///moIniFile.Readstring('frmMain','00908','');
Columns[1].Caption:='22';///moIniFile.Readstring('frmMain','00909','');
Columns[2].Caption:='22';///moIniFile.Readstring('frmMain','00910','');
Columns[3].Caption:='22';///moIniFile.Readstring('frmMain','00911','');
Columns[4].Caption:='22';///moIniFile.Readstring('frmMain','00912','');
Columns[5].Caption:='22';///moIniFile.Readstring('frmMain','00913',''); sngWidth:=(Width)*0.1;
Columns[0].Width:=round(sngWidth*0.4);
Columns[1].Width:=round(sngWidth*0.8);
Columns[2].Width:=round(sngWidth*0.8);
columns[3].Width:=round(sngWidth*1.2);
Columns[4].Width:=round(sngWidth*1.75);
Columns[5].Width:=round(sngWidth*5.0);
end;
except end;
end;procedure TForm1.AddInfoToListView;
var
bytI:byte;
begin
for bytI := 0 to 9 do
begin
with ListView1.Items.Add do
begin
SubItems.Add(inttostr(bytI));
SubItems.Add(inttostr(bytI));
SubItems.Add(inttostr(bytI));
SubItems.Add(inttostr(bytI));
SubItems.Add(inttostr(bytI));
ImageIndex:=1;
end;
end;
StatusBar1.Panels.Items[0].Text:='ListView1.Items.Count='
+inttostr(ListView1.Items.Count);
end;procedure TForm1.ListView1DblClick(Sender: TObject);
var
str1:string;
str2:string;
str3:string;
begin
///////
if ListView1.SelCount>0 then
begin
/////str1:=ListView1.Selected.SubItems.Strings[0];
str2:=ListView1.Selected.SubItems.Strings[1];
str3:=ListView1.Selected.SubItems.Strings[2];
str1:=ListView1.Items[2].SubItems[0];
showmessage('str1: '+str1+' str2: '+str2+' str3: '+str3);
end;
end;