1

I am using the TGrid in FM and want users to be able to resize a column, but not re-organise the columns (ie. drag & move the column header). I have tried changing many of the exposed properties ("Locked", "DragMode", "EnableDrag" etc...) - but nothing appears to have the desired effect?

In true FM experience; I am guessing that I may have to override the class and change something at the back-end structure; but am unsure what/where - or even if this is feasible?

Sample source wise; you can see the issue if you simply add a TGrid, add a few columns and run.

Many thanks in advance. Ian.

Ian
  • 147
  • 1
  • 3
  • 8

1 Answers1

2
type
  TCustomGridHelper = class helper for TCustomGrid
  public
    /// <summary>
    /// Publish private FHeader from FMX.Grid.TCustomGrid.
    /// </summary>
    function _GetHeader: THeader;
  end;

function TCustomGridHelper._GetHeader: THeader;
begin
  Result := Self.FHeader;
end;

procedure TForm1.Grid1ApplyStyleLookup(Sender: TObject);
var
  I: Integer;
  Header: THeader;
  HeaderItem: THeaderItem;
begin
  Header := Grid1._GetHeader;
  for I := 0 to Header.ChildrenCount - 1 do
  begin
    HeaderItem := Header.Children[I] as THeaderItem;
    HeaderItem.DragMode := TDragMode.dmManual;
  end;
end;
tz.
  • 731
  • 7
  • 13
  • Hi Tz - thanks again; but I have noticed a slight issue that is most likley down to how I use the TGrid and wondered if there is a way around it? I use the TGrid for many different scenarios, so I destroy the columns and re-add them . When I do, the "drag prevention" is lost. As an example, I have a TGrid with 2 manual add columns. I then use Grid1.ColumnByIndex(1).Destroy; Grid1.ColumnByIndex(0).Destroy;and re-add 2 new columns with Grid1.AddObject(TStringColumn.Create(Grid1)); - this time I can drag again? - Is there a way around this at all? - Thx – Ian Feb 19 '12 at 23:07
  • Resolved the above issue (of delete/re-creating elements of grid) by ensuring that the StyleLookup is reset on the Grid following the destroy/recreate of your columns? - Obviously some weird FM (v1) logic... (;-> – Ian Feb 25 '12 at 12:13