Hola Gydba
Ante todo gracias por el código, pero ya lo había implementado cuando lo he leído
Por cierto, lo has probado? Si quieres usar ese componente, te aconsejo que lo hagas
Yo lo he probado y me daba Access Violations. He corregido ese error cambiando el procedimiento ColWidthsChanged de esta manera
Código Delphi
[-]
procedure TCustomDBGrid1.ColWidthsChanged;
begin
inherited ColWidthsChanged;
if DataLink.Active then
if not bColMoved then begin
if Assigned(varColWidthChg) then varColWidthChg(Self, varCurrentCell.X);
end;
bColMoved := False;
end;
pero ahora me devolvía siempre una columna más de la que tocaba (cosa que ya desistí mirarme).
Mira lo que yo he hecho (por si interesa a alguien)
Si me he dejado algo o me sobra algo, ya me perdonaréis, pero es que el componente tiene otras funciones (y no es plan de poner todo el código). Si queréis ver el código completo, en breves lo subiré a mi web (a la que termine unos detallitos más, seguramente este finde).
Código Delphi
[-]
type
TColumnResized = procedure(Sender: TObject; Column: TColumn) of object;
TExtendedGrid = class(TRxDbGrid)
private
FListCols: TDBGridColumns;
FOnColumnResized: TColumnResized;
function MismasColumnas: boolean;
protected
procedure LinkActive(Value: Boolean); override;
procedure ColWidthsChanged; override;
procedure ColumnMoved(FromIndex, ToIndex: Longint); override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property OnColumnResized: TColumnResized read FOnColumnResized write FOnColumnResized;
end;
implementation
function TExtendedGrid.MismasColumnas: boolean;
var
i: integer;
begin
Result := false;
i := 0;
if FListCols.Count <> DataSource.DataSet.Fields.Count then
Exit;
while (i <= DataSource.DataSet.Fields.Count - 1) and not Result do
begin
if DataSource.DataSet.Fields[i].FieldName = TColumn(FListCols[i]).Field.FieldName then
inc(i)
else
Result := true;
end;
end;
procedure TExtendedGrid.LinkActive(Value: Boolean);
begin
inherited;
if not Value then
Exit
else
begin
Ok := MismasColumnas;
FListCols.Clear;
FListCols.Assign(Self.Columns);
if Ok then Exit;
end;
end;
procedure TExtendedGrid.ColWidthsChanged;
var
i: Integer;
begin
inherited;
if Columns.Count <> FListCols.Count then
Exit;
for i := 0 to Columns.Count - 1 do
if Columns.Items[i].Width <> FListCols.Items[i].Width then
if Assigned(OnColumnResized) then
OnColumnResized(Self, Columns.Items[i]);
FListCols.Clear;
FListCols.Assign(Columns);
end;
procedure TExtendedGrid.ColumnMoved(FromIndex, ToIndex: Integer);
begin
FListCols.Clear;
FListCols.Assign(Columns);
inherited;
end;
constructor TExtendedGrid.Create(AOwner: TComponent);
begin
inherited;
FListCols := TDBGridColumns.Create(Self, TColumn);
end;
destructor TExtendedGrid.Destroy;
begin
FreeAndNil(FListCols);
inherited;
end;
Seguramente es algo más liado que lo tuyo, pero me interesaba poder pasar un TColumn y, a parte, así podré controlar otras cosillas que tengo en mente
Nos leemos