Firemonkey Grid Control - Disable column move; yet allow column sizing
-
27-10-2019 - |
Pergunta
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.
Solução
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;
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow