procedure TxmzdForm.stglszdKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (key=VK_DOWN) and (stglszd.row = stglszd.RowCount-1) and (trim(stglszd.Cells[3,stglszd.row])<>'') then
AppendRow(stglszd.Row); if (key=VK_UP) and (stglszd.row = stglszd.RowCount-1) and (trim(stglszd.Cells[3,stglszd.row])='') then
DeleteRow(stglszd.Row);
end;procedure TxmzdForm.DeleteRow(RowNum: integer);
var i: integer;
begin
with stglszd do
begin
if RowNum<= fixedrows-1 then exit;
if RowNum > rowcount-1 then exit;
if RowNum <= rowcount-1 then begin
if RowCount=FixedRows+1 then begin
Rows[RowCount-1].Clear;
exit;
end;
for i:=RowNum to RowCount-2 do Rows[i]:=Rows[i+1];
RowCount:=RowCount-1;
if RowNum > stglszd.RowCount-stglszd.FixedCols then
stglszd.Row:= stglszd.RowCount-stglszd.FixedCols;
end;
end;
end;stglszd是一个stringgrid.当最后一条记录按上前头时,stringgrid删除一行,但光标仍然留在被删除行位置,如果用鼠标点击该stringgrid,光标才回到当前最后一行。该怎么解决?
Shift: TShiftState);
begin
if (key=VK_DOWN) and (stglszd.row = stglszd.RowCount-1) and (trim(stglszd.Cells[3,stglszd.row])<>'') then
AppendRow(stglszd.Row); if (key=VK_UP) and (stglszd.row = stglszd.RowCount-1) and (trim(stglszd.Cells[3,stglszd.row])='') then
DeleteRow(stglszd.Row);
end;procedure TxmzdForm.DeleteRow(RowNum: integer);
var i: integer;
begin
with stglszd do
begin
if RowNum<= fixedrows-1 then exit;
if RowNum > rowcount-1 then exit;
if RowNum <= rowcount-1 then begin
if RowCount=FixedRows+1 then begin
Rows[RowCount-1].Clear;
exit;
end;
for i:=RowNum to RowCount-2 do Rows[i]:=Rows[i+1];
RowCount:=RowCount-1;
if RowNum > stglszd.RowCount-stglszd.FixedCols then
stglszd.Row:= stglszd.RowCount-stglszd.FixedCols;
end;
end;
end;stglszd是一个stringgrid.当最后一条记录按上前头时,stringgrid删除一行,但光标仍然留在被删除行位置,如果用鼠标点击该stringgrid,光标才回到当前最后一行。该怎么解决?
{25}procedure DeleteRow(STringGrid: TSTringGrid; Row: integer);
var
I_row: Integer;
I_col: Integer;
begin
if (StringGrid.RowCount-1)=Row then //如果是最后1行
For I_col:=1 to StringGrid.ColCount -1 do
StringGrid.Cells[I_col,Row]:='';
//----------------------------------------------------------------------
for I_row:=Row to StringGrid.RowCount-1 do
begin
For I_col:=1 to StringGrid.ColCount-1 do
begin
if I_row=StringGrid.RowCount-1 then //到最后1行时
STringGrid.Cells[I_col,I_row]:=''
else
begin
STringGrid.Cells[I_col,I_row]:=STringGrid.Cells[I_col,I_row+1];
end;
end;
end;
end;
stringgrid.cells[0,0] = '';
stringgrid.cells[0,1] = '';
...