StringGrid中现在显示有数据,我想实现双击某行就删除这行的数据,并且这行以下的数据上移一行,这样刚删除的那行就不会有空行出现。谢谢!我在线。
解决方案 »
- 有米有 Indy 的 Idhttp 滴教程或源码什么的??
- 句柄无法获取到,试过很多都没有得到
- 但是Create(self),Create(nil) 有什么区别啊
- ▁▂▄▅▆▇█▉100个QQ号免费奉送,呵呵~~▉█▇▆▅▄▂▁
- 如何释放动态链表?
- 当我TADOQuery控件去链接台数据表中的char字段,在界面上用TDBGrid控件去修改数据时,好象有问题。
- canvas画布的字体如何竖着写?
- 如何用Delphi在SQL Server中建立存储过程??请各位多多帮忙!!
- 谁能告诉我,关于数据库有什么好书,thanks a lot!(mm)
- 大家一起进来:简单问题
- 用DELPHI6调用Webservice,返回内容有照片的XML,在程序中就报个错误,谁知道怎么回事?
- 我想实现按F1-F12键触发一段程序,怎么实现?要用到哪些控件?怎么设置?
然后就先将本行的设为‘’,有个col和row的属性就是当前选中的那行,然后逐行上移就好啦:)
var
i,j:integer;
begin
StringGrid1.RowCount:=StrToInt(Edit1.Text);
StringGrid1.ColCount:=StrToInt(Edit2.Text);
for i:=0 to StrToInt(Edit1.Text)-1 do
for j:=0 to StrToInt(Edit2.Text)-1 do
begin
StringGrid1.Cells[j,i]:=IntToStr(i*j);
end;
end;procedure TForm1.StringGrid1DblClick(Sender: TObject);
var
iPos:integer;
i,j:integer;
begin
iPos:=StringGrid1.Selection.Top;
for i:=iPos to StringGrid1.RowCount-2 do
begin
for j:=0 to StringGrid1.ColCount-1 do
begin
StringGrid1.Cells[j,i]:=StringGrid1.Cells[j,i+1];
end;
end;
StringGrid1.RowCount:=StringGrid1.RowCount-1;
end;
iPos:integer;
i,j:integer;
begin
iPos:=StringGrid1.Selection.Top;
for i:=iPos to StringGrid1.RowCount-2 do //HERE
begin
for j:=0 to StringGrid1.ColCount-1 do
begin
StringGrid1.Cells[j,i]:=StringGrid1.Cells[j,i+1];
end;
end;
StringGrid1.RowCount:=StringGrid1.RowCount-1;
end;
--------------------------------------------------------------------
不明白为什么前面FOR语句结束要少一位,StringGrid1.RowCount-2,这样写的结果是导致最后一条数据无法删除。
老兄,试过没有啊。写成RowCount-2当然有RowCount-2的理由啊。
因为循环到这里就能够完成对数据的赋值了,
否则StringGrid1.Cells[j,i+1];是不是越界啦。
var
i,j:integer;
s:string;
begin
for j:=SGDelete.Row to SGDelete.RowCount-2 do
for i:=1 to SGDelete.ColCount-1 do
SGDelete.Cells[i,j]:=SGDelete.Cells[i,j+1];
SGDelete.RowCount:=SGDelete.RowCount-1;
end;
“StringGrid1.RowCount-2,这样写的结果是导致最后一条数据无法删除。”
没看到最后一句吗?SGDelete.RowCount:=SGDelete.RowCount-1;这样就把最后一行删除掉了。
SGDelete.RowCount:=SGDelete.RowCount-1;这好象是把SGDelete的列数减一吧。
TO gzmhero(hihihi) :
的确写成-1会越界,但写成-2应该的确是最后一条记录无法删除,测试了。
可以寻求更好的解决办法,当然,比直接覆盖这样的办法麻烦一点。
StringGrid一定要有一行在显示,不能删除这一行,不过可以赋空值。 if StringGrid1.RowCount<2 then
begin
for j:=0 to StringGrid1.ColCount-1 do
StringGrid1.Cells[j,0]:='';
end else
begin
for i:=iPos to StringGrid1.RowCount-2 do
begin
for j:=0 to StringGrid1.ColCount-1 do
begin
StringGrid1.Cells[j,i]:=StringGrid1.Cells[j,i+1];
end;
end;
StringGrid1.RowCount:=StringGrid1.RowCount-1;
end;