我在form中设置了2个stringgrid。我想把第一个stringgrid的数据有条件的导入到第二个stringgrid中,条件是大于某一列的值,运行时,前三列有数据,从这之后stringgrid中就没数据了,代码如下,请大家帮个忙,解决一下。procedure TForm1.Button5Click(Sender: TObject);
var
i,j,ccount:integer;
begin
ccount:=StringGrid1.ColCount;
for i:=1 to StringGrid1.RowCount do
begin
stringgrid2.Cells[1,i]:=stringgrid1.Cells[1,i];
stringgrid2.Cells[2,i]:=stringgrid1.Cells[2,i];
stringgrid2.Cells[3,i]:=stringgrid1.Cells[3,i]; for j:=4 to ccount-10 do //数据比较多
begin
if stringgrid1.Cells[j,i]>stringgrid1.Cells[ccount-3,i] then //每一个值和倒数第三列的值比较,谁小,取谁
stringgrid2.Cells[j,i]:=stringgrid1.Cells[ccount-3,i] else
stringgrid2.Cells[j,i]:=stringgrid1.Cells[j,i];
end;
end;
showmessage('数据替换成功!')
end;
var
i,j,ccount:integer;
begin
ccount:=StringGrid1.ColCount;
for i:=1 to StringGrid1.RowCount do
begin
stringgrid2.Cells[1,i]:=stringgrid1.Cells[1,i];
stringgrid2.Cells[2,i]:=stringgrid1.Cells[2,i];
stringgrid2.Cells[3,i]:=stringgrid1.Cells[3,i]; for j:=4 to ccount-10 do //数据比较多
begin
if stringgrid1.Cells[j,i]>stringgrid1.Cells[ccount-3,i] then //每一个值和倒数第三列的值比较,谁小,取谁
stringgrid2.Cells[j,i]:=stringgrid1.Cells[ccount-3,i] else
stringgrid2.Cells[j,i]:=stringgrid1.Cells[j,i];
end;
end;
showmessage('数据替换成功!')
end;
解决方案 »
- Delphi RzPageControl多个DBGrid选择问题
- 昨晚在东莞惨遭飞抢, 运气好没被抢到, 散400分消灾(1)
- 关于 dbchart ,请帮忙!
- 关于Olecontainer如何保存文件文件名的问题,50分
- 请教用delphi开发数据库接口的思路
- DELPHI客户端引入WSDL单元之后,程序异常!!
- 執行ApplyUpdates,出現Remote Error....
- 我想问:怎样单击speenbutton,弹出一个菜单
- 求助DateTimePicker.date在程序中如何把他清空!!!!!!!!
- 取sql server的查询结果?
- 请教大家一个新手的问题.求2数a,b的和!!!
- Delphi 调用WebService(C#) 接收到的XML数据 中文乱码
if strtoint(stringgrid1.Cells[j,i])>strtoint(stringgrid1.Cells[ccount-3,i]) then 如果表格中有小数,就改成
if strtofloat(stringgrid1.Cells[j,i])>strtofloat(stringgrid1.Cells[ccount-3,i]) then
大家看一下这段代码就清楚了:
for j:=4 to ccount-10 do //数据比较多
begin
if stringgrid1.Cells[j,i]>stringgrid1.Cells[ccount-3,i] then
stringgrid2.Cells[j,i]:=stringgrid1.Cells[ccount-3,i] else
stringgrid2.Cells[j,i]:=stringgrid1.Cells[j,i];
end;
begin
if stringgrid1.Cells[j,i]<>'' then
begin
if strtofloat(stringgrid1.Cells[j,i])>strtofloat(stringgrid1.Cells[ccount-3,i]) then
stringgrid2.Cells[j,i]:=stringgrid1.Cells[ccount-3,i] else
stringgrid2.Cells[j,i]:=stringgrid1.Cells[j,i];
end else
begin
......//这儿写数据为空时的操作
end;