destructor TKDBGrid.Destroy;
begin
FTitlePanel.Free;
inherited;
end;
function TKDBGrid.CellsTotalWidth: Integer;
var
I : Integer;
begin
Result := 0;
for I := 0 to Self.Columns.Count - 1 do
Result := Result + Self.Columns[I].Width + Self.GridLineWidth;
Result := Result + (Self.CellRect(0,0).Right - Self.CellRect(0,0).Left);
end;
procedure TKDBGrid.ColWidthsChanged;
begin
inherited;
SetTitlePanelStatus;
end;
procedure TKDBGrid.DrawCell(ACol, ARow: Integer; ARect: TRect;
AState: TGridDrawState);
begin
inherited;
if Self.LeftCol <> FLastLeftCol then begin
SetTitlePanelStatus;
FLastLeftCol := Self.LeftCol;
end;
end;
procedure TKDBGrid.SetSpecialTitle(Value: Boolean);
begin
if Value <> FSpecialTitle then
FSpecialTitle := Value;
end;
procedure TKDBGrid.SetTitlePanelStatus;
function GetLabelLeft(Count : Integer) : Integer;
var
I ,MyWidth : Integer;
begin
MyWidth := 0;
Result := 0;
for I := 0 to Count - 1 do
MyWidth := MyWidth + Self.Columns[I].Width + Self.GridLineWidth;
MyWidth := MyWidth + (Self.CellRect(0,0).Right - Self.CellRect(0,0).Left);
Result := MyWidth;
end;
//
function GetPanelLeft : Integer;
var
I : Integer;
begin
Result := 0;
for I := 0 to Self.LeftCol - 2 do
Result := Result + Self.Columns[I].Width + Self.GridLineWidth;
Result := 0 - Result;
end;
var
I : Integer;
MyLabel : TLabel;
begin
if not FSpecialTitle then begin
FTitlePanel.Visible := False;
Exit;
end;
//
with FTitlePanel do begin
Parent := Self;
Visible := False;
Width := CellsTotalWidth;
Height := Self.CellRect(0,0).Bottom - Self.CellRect(0,0).Top;
Left := GetPanelLeft;
Top := 0;
Visible := True;
end;
for I := FTitlePanel.ComponentCount -1 downto 0 do
if FTitlePanel.Components[I] is TLabel then TLabel(FTitlePanel.Components[I]).Free;
for I := 0 to Self.Columns.Count - 1 do begin
MyLabel := TLabel.Create(FTitlePanel);
MyLabel.Parent := FTitlePanel;
MyLabel.Top := Round((FTitlePanel.Height - MyLabel.Height)/2) + 1;
MyLabel.Font := Self.Columns[I].Title.Font;
MyLabel.Left := GetLabelLeft(I);
MyLabel.Caption := Self.Columns[I].Title.Caption;
MyLabel.Visible := True;
end;
end;