delphi编程, 如何实现赋值StringGrid表格内的数字按顺序排列

要达到这种效果
是我弄错图片了

从小到大排列,用个简单的冒泡排序法就好了。
procedure TForm1.Button1Click(Sender: TObject);
var
i,j:Integer;
tmp:Double;
begin
for i:=0 to StringGrid1.RowCount-2 do
begin
if StringGrid1.Cells[0,i]='' then continue;
for j:=i to StringGrid1.RowCount -2 do
begin
if StrToFloat(StringGrid1.Cells[0,j]) > StrToFloat(StringGrid1.Cells[0,j+1]) then
begin
tmp:=StrToFloat(StringGrid1.Cells[0,j+1]);
StringGrid1.Cells[0,j+1] := StringGrid1.Cells[0,j];
StringGrid1.Cells[0,j]:=FloatToStr(tmp);
end;
end;
end;
end;
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-09-12
弄一数据库,搞一个表,字段为数字类型,界面用一个DBGRID,ADO数据连接组件中,指明排序方式就行了。冒泡排序,还要重写StringGrid挺麻烦的。
第2个回答  2013-09-12
你两个图没区别啊
相似回答