procedure TForm1.DeleteClick(Sender: TObject);
var
i:integer;
begin
for i:=1 to StringGrid1.RowCount-1 do
StringGrid1.Rows[i].Assign(StringGrid1.Rows[i+1]);
end;//删除第二行
不就是删除
procedure TForm1.deleteClick(Sender: TObject);
var
i_row,j_col:integer;
begin
stringgrid1.Rows[stringgrid1.row].Clear;
for j_col:=0 to stringgrid1.colcount do
for i_row:=stringgrid1.Row to stringgrid1.rowcount-1 do
stringgrid1.cells[j_col,i_row]:=stringgrid1.cells[j_col,i_row+1];
stringgrid1.RowCount:=stringgrid1.RowCount-1;
stringgrid1.Refresh;
i:=删除行号
for j:= i to stringgrid.rowcount - 2 do
begin
stringgrid.rows[j].clear;
stringgrid.rows[j].addstrings(stringgrid.rows[j+1])
end;
stringgrid.rows[stringgrid.rowcount-1].clear;
stringgrid.rowcount := stringgrid.rowcount - 1;
有什么方法可以通过光标控制键来选择stringgrid中的整行呢?
option-rowselect/rowselection? =true
procedure del_current_row(grid:Tstringgrid);
var
temstr:Tstrings;
delrow,col,i,j,m_tag:integer;
label l;
begin
m_tag:=0;
delrow:=grid.Row;
for i:=delrow to grid.RowCount-1 do
begin
for j:=0 to grid.colcount-1 do
begin
if length(trim(grid.Cells[0,i]))=0 then
begin
// grid.RowCount:=4;
m_tag:=i;
goto l;
end
else
begin
grid.Cells[j,i]:=grid.Cells[j,i+1];
m_tag:=i;
end;
end;
end;
l:
grid.Rows[m_tag].Clear;
grid.tag:=m_tag;
if grid.RowCount>4 then
grid.RowCount:=grid.RowCount-1;
end;
1.
procedure TForm1.DeleteClick(Sender: TObject);
var
i:integer;
begin
for i:=1 to StringGrid1.RowCount-1 do
StringGrid1.Rows[i].Assign(StringGrid1.Rows[i+1]);
end;//删除第二行
2.设置StringGrid1的Option中的goRowSelect为真就可选一行。这样你可以在程序中来控件如何选择一行了