0
votes

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

1
columns, rows... Please, can you elaborate what exactly should and what should not be possible for user ? maybe some PNG screenshots with arrows highlighting the chanegs ? i cannot understand a bit...Arioch 'The
docwiki.embarcadero.com/Libraries/XE5/en/… This suggests that any column and row can be sized, did you set it right ?Arioch 'The
The issue being referred to here is that Delphi (AFIAK) will only set the mouse 'resize' cursor for columns when it is over the header row (fixed row).Matt Allwood
Yes, Matt Allwood has identifies the issue. I want all the cells to look the same, but you can only resize columns when at least one is fixed (FixedRows := 1) and you can't show a grid with all rows fixed. I was doing grid.FixedRows := grid.RowCount and it wouldn't take that.Mark Patterson
What I have done is add a sort of header row. I now have one fixed row and one fixed column. This has the unintended consequence that I can adjust the widths of all rows, except row 0.Mark Patterson

1 Answers

1
votes

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;