private
procedure DynamicGridSelector(Sender: TObject);
//...
procedure TForm1.DynamicGridSelector(Sender: TObject);
var
i : integer;
begin
with TStringGrid(Sender)
do
begin
for i := 0
to ColCount - 1
do
Objects[i, 0] := TObject(i
in [Selection.Left..Selection.Right]);
for i := 0
to RowCount - 1
do
Objects[0, i] := TObject(i
in [Selection.Top..Selection.Bottom]);
end;
end;
procedure TForm1.SGDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect; State: TGridDrawState);
var
vRect: TRect;
begin
with TStringGrid(Sender)
do
begin
// Überschriften
if (gdFixed
in State)
then
begin
if LongBool(Objects[ACol, ARow])
then
begin
Canvas.Font.Color :=
RGB(255,255,255);
Canvas.Brush.Color :=
RGB(240,0,120);
end;
end;
// GridFelder
if (gdSelected
in State)
and not (gdFixed
in State)
then
begin
Canvas.Font.Color :=
RGB(255,255,255);
Canvas.Font.Style := [fsBold];
Canvas.Brush.Color :=
RGB(240,0,120);
end;
// Dummy
vRect.Top := Rect.Top;
vRect.Left := Rect.Left-4;
vRect.Right := Rect.Right;
vRect.Bottom := Rect.Bottom;
Canvas.FillRect(vRect);
Canvas.TextOut(Rect.Left+2, Rect.Top+2, SG.Cells[ACol, ARow]);
end;
end;
procedure TForm1.SGMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
DynamicGridSelector(Sender);
end;
procedure TForm1.SGMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
DynamicGridSelector(Sender);
end;