注册 登录
编程论坛 Delphi论坛

[求助]有关stringgrid的问题

BCheng112415 发布于 2006-11-01 17:03, 724 次点击

我想显示时间到stringgrid1.cells上,
代码是:
procedure TForm1.Button1Click(Sender: TObject);
var
i,j:integer;
s:array[1..10,1..10]of string;
rect:trect;
begin

for i:=1 to 5 do
case j of
1: stringgrid1.Cells[j,i]:=timetostr(DateTimePicker3.DateTime);
else stringgrid1.Cells[j,i]:='nihao';
end;
s[i,j]:=stringgrid1.Cells[j,i];
for i:=1 to 5 do
for j:=1 to 5 do
begin
rect:=stringgrid1.cellrect(j,i);
stringgrid1.canvas.textout(rect.left,rect.top,s[i,j]);
end;
end;

6 回复
#2
xu20002006-11-01 23:54
for i:=1 to 5 do
case j of
1: stringgrid1.Cells[j,i]:=timetostr(DateTimePicker3.DateTime);
else stringgrid1.Cells[j,i]:='nihao';
end;
在这段代码之前,j是多少?
#3
BCheng1124152006-11-02 13:55
先谢谢,我在这没定义过j,就是这样,可以运行,却不能显示结果.
#4
volte2006-11-02 16:46

procedure TForm1.Button1Click(Sender: TObject);
var
i,j:integer;
begin
StringGrid.rowcount := 7;
for j:=1 to 5 do
begin
for i:=1 to 5 do
begin
if j = 1 then
StringGrid.Cells[j, i] := FormatDateTime('yyyy-MM-dd hh:mm:ss', DateTimePicker3.DateTime);
else
StringGrid.Cells[j, i] := 'nihao';
end;
end;
end;

#5
BCheng1124152006-11-03 10:25

谢谢!!终于可以了!!

#6
BCheng1124152006-11-03 11:51
不过我还是有疑问!!stringgrid.后面不会直接显示cells[x,y]属性;为什么??
#7
volte2006-11-03 16:41
这个是控件的问题。
也可能是你装的控件有问题!

不过在COM+编程时候也会出现这样的事情!
我在用COM+编程时候就出现这样的问题,不过习惯了就行了。
有时候如果纯粹的去等它响应,
还感觉在浪费时间。

有兴趣,你可以看看别人写的控件代码。
1