本文介绍了删除StringGrid- Delphi中的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想做类似的事情.我的StringGrid中有一个列表,我想通过选择单元格然后单击按钮来删除一行.然后,此列表应再次显示在StringGrid中而不包含此行.我认为删除行是最大的问题,我尝试了一种方法,但我认为它仅删除StringGrid中的行,而不删除列表中的行.
I want to make something like that. I have a list in my StringGrid and i want to delete one row by selecting cell and then clicking the button. Then this list should show again in StringGrid without this row. The biggest problem i have with deleting row, i tried whis one procedure but it only deleted row in StringGrid, not in list, i think.
procedure DeleteRow(Grid: TStringGrid; ARow: Integer);
var
i: Integer;
begin
for i := ARow to Grid.RowCount - 2 do
Grid.Rows[i].Assign(Grid.Rows[i + 1]);
Grid.RowCount := Grid.RowCount - 1;
end;
请帮助.:)
推荐答案
可以在 StringGrid1.selected
中检索选定的行,然后可以调用以下过程.
The selected row can be retrieved StringGrid1.selected
and the you can call the following procedure.
procedure TUtils.DeleteRow(ARowIndex: Integer; AGrid: TStringGrid);
var
i, j: Integer;
begin
with AGrid do
begin
if (ARowIndex = RowCount) then
RowCount := RowCount - 1
else
begin
for i := ARowIndex to RowCount do
for j := 0 to ColumnCount do
Cells[j, i] := Cells[j, i + 1];
RowCount := RowCount - 1;
end;
end;
end;
这篇关于删除StringGrid- Delphi中的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!