【发布时间】:2012-01-04 16:46:21
【问题描述】:
我正在尝试将stringgrid1 和stringgrid2 分别替换为listbox1 和listbox2。他们有什么办法我可以做到吗?如果listbox 不能做任何人可以建议我应该使用什么来代替stringgrid 来显示信息?我是 Delphi 的新手。
这是我的代码:
procedure TForm2.FormCreate(Sender: TObject);
var i:integer;
begin
stringgrid1.ColWidths[0]:=20;
stringgrid2.ColWidths[0]:=20;
for i:=1 to 50 do begin
stringgrid1.Cells[0,i]:=inttostr(i-1);
stringgrid2.Cells[0,i]:=inttostr(i-1);
stringgrid2.Cells[1,i]:='0';
end;
stringgrid2.Cells[1,0]:='name';
stringgrid1.Cells[1,0]:='extension';
stringgrid1.Cells[2,0]:='format';
stringgrid1.Cells[3,0]:='size';
stringgrid1.Cells[4,0]:='date';
stringgrid1.Cells[5,0]:='addres';
end;
procedure TForm2.StringGrid2DblClick(Sender: TObject);
begin
if (stringgrid2.Cells[1,stringgrid2.Row]<>'1024') and (stringgrid2.Cells[1,stringgrid2.Row]<>'0') then
stringgrid1.Row:=strtoint(stringgrid2.Cells[1,stringgrid2.Row]);
end;
结束。
Procedure HD;
var i:integer;
begin
for i:=0 to 50 do begin
form2.StringGrid1.Cells[1,i+1]:=TABLE[i].name;
form2.StringGrid1.Cells[2,i+1]:=TABLE[i].format;
if TABLE[i].tip then
form2.StringGrid1.Cells[3,i+1]:='folder'
else
form2.StringGrid1.Cells[3,i+1]:='file';
form2.StringGrid1.Cells[4,i+1]:=inttostr(TABLE[i].nach);
form2.StringGrid1.Cells[5,i+1]:=inttostr(TABLE[i].razmer);
form2.StringGrid2.Cells[1,i+1]:=inttostr(fat[i]);;
end;
end;
【问题讨论】:
-
由于您有多个列,因此您需要
vsReport视图样式中的TListView而不是列表框。 -
怎么能把它放到我的代码里?直接替换它
-
查看这些示例,并阅读文档。 ListItemSubItemsListItemsInsert
-
欢迎堆栈溢出。很高兴您发布了一些代码,但是下次您提出问题时,请详细说明您要对代码执行的操作。例句:“我想显示文件夹和文件大小,还想在第三列显示一些图片,但我不知道如何使用 TStringGrid 来做到这一点”。
-
重新发布 David 的链接并修复第二个链接(以防万一):ListItemSubItems、ListItemsInsert。
标签: delphi