Procedure GridRemoveColumn(StrGrid: TStringGrid; DelColumn: Integer);
Var Column: Integer;
begin
If DelColumn <= StrGrid.ColCount then
Begin
For Column := DelColumn To StrGrid.ColCount-1 do
StrGrid.Cols[Column-1].Assign(StrGrid.Cols[Column]);
StrGrid.ColCount := StrGrid.ColCount-1;
End;
end;
Procedure GridAddColumn(StrGrid: TStringGrid; NewColumn: Integer);
Var Column: Integer;
begin
StrGrid.ColCount := StrGrid.ColCount+1;
For Column := StrGrid.ColCount-1 downto NewColumn do
StrGrid.Cols[Column].Assign(StrGrid.Cols[Column-1]);
StrGrid.Cols[NewColumn-1].Text := '';
end;
Procedure GridSort(StrGrid: TStringGrid; NoColumn: Integer);
Var Line, PosActual: Integer;
Row: TStrings;
begin
Renglon := TStringList.Create;
For Line := 1 to StrGrid.RowCount-1 do
Begin
PosActual := Line;
Row.Assign(TStringlist(StrGrid.Rows[PosActual]));
While True do
Begin
If (PosActual = 0) Or (StrToInt(Row.Strings[NoColumn-1]) >=
StrToInt(StrGrid.Cells[NoColumn-1,PosActual-1])) then
Break;
StrGrid.Rows[PosActual] := StrGrid.Rows[PosActual-1];
Dec(PosActual);
End;
If StrToInt(Row.Strings[NoColumn-1]) < StrToInt(StrGrid.Cells[NoColumn-1,PosActual]) then
StrGrid.Rows[PosActual] := Row;
End;
Renglon.Free;
end;
//删除Grid的一行记录
procedure GridDeleteRow(RowNumber:Integer;Grid:TstringGrid);
var
i :Integer;
begin
Grid.Row:=RowNumber;
if (Grid.Row=Grid.RowCount-1) then
{ On the last row}
Grid.RowCount:=Grid.RowCount-1
else
begin
{ Not the last row}
for i:=RowNumber to Grid.RowCount-1 do
Grid.Rows[i]:=Grid.Rows[i+1];
Grid.RowCount:=Grid.RowCount-1;
end;
end;
procedure Tf_MG_m.StringGrid1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var i,m,n,m1,m2,n1,n2:integer;
mgarray:array[0..100]of string;
begin
m1:=stringgrid1.selection.left;
n1:=stringgrid1.Selection.Top;
m2:=stringgrid1.Selection.Right;
n2:=stringgrid1.Selection.Bottom;
i:=0;
if (m1<>m2) and (n1<>n2) then
begin
//for m:=m1 to m2 do
for n:=n1 to n2 do
begin
mgarray[i]:=stringgrid1.Cells[0,n];
//memo1.Text:=('m1:'+inttostr(m1)+' n1:'+inttostr(n1)+' m2:'+inttostr(m2)+' n2:'+inttostr(n2));
memo1.Text:=memo1.Text+mgarray[i];
inc(i);
end;
end;
end;
end.
Var Column: Integer;
begin
If DelColumn <= StrGrid.ColCount then
Begin
For Column := DelColumn To StrGrid.ColCount-1 do
StrGrid.Cols[Column-1].Assign(StrGrid.Cols[Column]);
StrGrid.ColCount := StrGrid.ColCount-1;
End;
end;
Procedure GridAddColumn(StrGrid: TStringGrid; NewColumn: Integer);
Var Column: Integer;
begin
StrGrid.ColCount := StrGrid.ColCount+1;
For Column := StrGrid.ColCount-1 downto NewColumn do
StrGrid.Cols[Column].Assign(StrGrid.Cols[Column-1]);
StrGrid.Cols[NewColumn-1].Text := '';
end;
Procedure GridSort(StrGrid: TStringGrid; NoColumn: Integer);
Var Line, PosActual: Integer;
Row: TStrings;
begin
Renglon := TStringList.Create;
For Line := 1 to StrGrid.RowCount-1 do
Begin
PosActual := Line;
Row.Assign(TStringlist(StrGrid.Rows[PosActual]));
While True do
Begin
If (PosActual = 0) Or (StrToInt(Row.Strings[NoColumn-1]) >=
StrToInt(StrGrid.Cells[NoColumn-1,PosActual-1])) then
Break;
StrGrid.Rows[PosActual] := StrGrid.Rows[PosActual-1];
Dec(PosActual);
End;
If StrToInt(Row.Strings[NoColumn-1]) < StrToInt(StrGrid.Cells[NoColumn-1,PosActual]) then
StrGrid.Rows[PosActual] := Row;
End;
Renglon.Free;
end;
//删除Grid的一行记录
procedure GridDeleteRow(RowNumber:Integer;Grid:TstringGrid);
var
i :Integer;
begin
Grid.Row:=RowNumber;
if (Grid.Row=Grid.RowCount-1) then
{ On the last row}
Grid.RowCount:=Grid.RowCount-1
else
begin
{ Not the last row}
for i:=RowNumber to Grid.RowCount-1 do
Grid.Rows[i]:=Grid.Rows[i+1];
Grid.RowCount:=Grid.RowCount-1;
end;
end;
procedure Tf_MG_m.StringGrid1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var i,m,n,m1,m2,n1,n2:integer;
mgarray:array[0..100]of string;
begin
m1:=stringgrid1.selection.left;
n1:=stringgrid1.Selection.Top;
m2:=stringgrid1.Selection.Right;
n2:=stringgrid1.Selection.Bottom;
i:=0;
if (m1<>m2) and (n1<>n2) then
begin
//for m:=m1 to m2 do
for n:=n1 to n2 do
begin
mgarray[i]:=stringgrid1.Cells[0,n];
//memo1.Text:=('m1:'+inttostr(m1)+' n1:'+inttostr(n1)+' m2:'+inttostr(m2)+' n2:'+inttostr(n2));
memo1.Text:=memo1.Text+mgarray[i];
inc(i);
end;
end;
end;
end.