Make the StringGrid like Excel (Firemonkey Application)


I want to be able to select some cells in particular on a StringGrid component.
Like in this image:

I tried something like this:

procedure TCadDieta.Grid01DrawColumnCell(Sender: TObject; const Canvas: TCanvas;
const Column: TColumn; const [Ref] Bounds: TRectF; const Row: Integer;
const [Ref] Value: TValue; const State: TGridDrawStates);
RowColor : TBrush;
if ((Column.Index >= SelectedColBegin ) and (Column.Index <= SelectedColEnd))
and ((Row >= SelectdRowBegin) and (Row <= SelectedRowEnd)) then
RowColor := Tbrush.Create(TBrushKind.Solid,TAlphaColors.Alpha);
RowColor.Color := TAlphaColors.Blue;
Canvas.FillRect(Bounds, 0, 0, [], 1, RowColor);
{ perform default drawing }
TGrid(Sender).DefaultDrawColumnCell(Canvas, Column, Bounds, Row,
Value, State);

The variables SelectedRowBegin, SelectedRowEnd, SelectedColBegin, SelectedColEnd
are seted in the OnMouseDown and OnMouseUp StringGrid events, according with the index of the selected cell.

My code does not works so well, anyone has any idea?

Comments are closed.