TVertGrid — TStringGrid с возможностью заполнения в design-time



Автор: Дмитрий Логинов

Компонент TVertGrid представляет собой модифицированный TStringGrid.

В стандартный компонент добавлена возможность в режиме Design-time заполнять первую колонку (property Labels) и первую строку (property Titles) грида.

Если набранных строк в Labels больше, чем задано количество строк самого TVertGrid, то они будут автоматически добавлены. Аналогично и с количеством колонок (Titles). При уменьшении строк в свойствах Labels и Titles, количество строк и колонок самого грида не будет уменьшаться.

На скриншоте показано редактирование списка заголовков колонок. Количество строк в Titles это количество заполненных колонок первой строки.

Компонент очень прост и вы можете модифицировать его по своему собственному желанию.

Скачать VertGrid.Zip (1K)

Исходный код компонента:


unit VertGrid;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Grids, stdctrls;
type
TVertGrid = class(TStringGrid)
protected
{ Protected declarations }
procedure SetLines(Value: TStrings);
function GetLines: TStrings;
procedure SetTitles(Value: TStrings);
function GetTitles: TStrings;
public
constructor Create(AOwner: TComponent); override;
published
// Первая колонка
property Labels: TStrings read GetLines write SetLines;
// Первая строка
property Titles: TStrings read GetTitles write SetTitles;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Samples', [TVertGrid]);
end;
constructor TVertGrid.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
ColCount := 2;
DefaultRowHeight := 16;
end;
procedure TVertGrid.SetLines(Value: TStrings);
begin
if Value.Count > RowCount then
RowCount := Value.Count;
Cols[0].Assign(Value);
end;
procedure TVertGrid.SetTitles(Value: TStrings);
begin
if Value.Count > ColCount then
ColCount := Value.Count;
Rows[0].Assign(Value);
end;
function TVertGrid.GetLines: TStrings;
begin
result := Cols[0];
end;
function TVertGrid.GetTitles: TStrings;
begin
result := Rows[0];
end;
end.


Далее: Автоматический подбор ширины колонок для TStringGrid »»