I want to have a grid where all rows look the same In Delphi, how can i let the user resize TStringGrid columns without fixed rows? Normally you can only adjust the fixed rows, and you can't make the whole grid fixed.
I am using XE2.
TIA
Mark
I want to have a grid where all rows look the same In Delphi, how can i let the user resize TStringGrid columns without fixed rows? Normally you can only adjust the fixed rows, and you can't make the whole grid fixed.
I am using XE2.
TIA
Mark
You might override CalcSizingState.
Set
- State to gsRowSizing if your condition is met (in the example below check if Alt key is pressed in MouseMove) and
- Index to the Calculated Index from MouseDown using MouseToCell.
Some fine tuning might be necessary.
type
TStringGrid = Class(Grids.TStringGrid)
private
FIsSizing: Boolean;
FIndex: Integer;
procedure CalcSizingState(X, Y: Integer; var State: TGridState; var Index: Longint; var SizingPos, SizingOfs: Integer; var FixedInfo: TGridDrawInfo); override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
private
End;
TForm3 = class(TForm)
StringGrid1: TStringGrid;
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form3: TForm3;
implementation
{$R *.dfm}
{ TStringGrid }
procedure TStringGrid.CalcSizingState(X, Y: Integer; var State: TGridState; var Index, SizingPos, SizingOfs: Integer; var FixedInfo: TGridDrawInfo);
begin
inherited;
if FIsSizing then
State := gsRowSizing;
if (FIndex > -1) then
begin
Index := FIndex;
end;
end;
procedure TStringGrid.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
Col: Integer;
begin
inherited;
MouseToCell(X, Y, Col, FIndex);
end;
procedure TStringGrid.MouseMove(Shift: TShiftState; X, Y: Integer);
begin
inherited;
FIsSizing := ssAlt in Shift;
end;