adding other controls to TStringGrid cells

how can I replace standard string grid cells with check boxes comboboxes or other control,  how do I paint (images) withing the cells ?
amielDorelAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ivanov_GCommented:
For drawing use OnCellDraw event:

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin
  // draw in [1,1] cell
  if (ACol = 1) and (ARow = 1) then
    begin
      Rect.Right := Rect.Right - 10;
      Rect.Bottom := Rect.Bottom - 10;
      StringGrid1.Canvas.Brush.Color := clRed;
      StringGrid1.Canvas.Pen.Color := clBlack;
      StringGrid1.Canvas.Rectangle(Rect);
    end;
end;

You can also choose some ready StringGrid component:
http://www.torry.net/pages.php?id=114
0
Eddie ShipmanAll-around developerCommented:
Here is Peter Below's contribution to the Borland newsgroups on how to add checkboxes to the column of a grid:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ComCtrls, Grids;

type
  TForm1 = class(TForm)
    StatusBar1: TStatusBar;
    StringGrid1: TStringGrid;
    procedure FormCreate(Sender: TObject);
    procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
    procedure StringGrid1TopLeftChanged(Sender: TObject);
    procedure gridcheckboxMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
var
  chk: TCheckbox;
  i: integer;
begin
  with stringgrid1 do begin
    rowcount := 30;
    colcount := 10;
    for i:= fixedrows to rowcount-1 do begin
      cells[1,i] := ' ';
      chk:= TCheckbox.Create( stringgrid1 );
      with chk do begin
        name := format('CellChk%d_%d',[1,i]);
        caption := '';
        checked := false;
        visible := false;
        parent  := stringgrid1;
        width   := height;
        OnMouseDown := gridcheckboxMouseDown;
      end;
      Objects[1,i] := chk;
    end;
  end;
end;

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
var
  chk: TCheckbox;
  grid: TStringgrid;
begin
  grid := Sender As TStringgrid;
  if (aCol = 1) and (aRow >= grid.FixedRows)
  then begin
    chk:= TCheckbox(grid.Objects[ aCol, aRow ]);
    If Assigned(chk) Then Begin
      chk.SetBounds( (rect.left + rect.right - chk.width) div 2,
                     (rect.top + rect.bottom - chk.height) div 2,
                     chk.width, chk.height );
      if not chk.visible then
        chk.show;
    End;
  end;

end;

type
  tgridcracker = Class( tstringgrid );

procedure TForm1.StringGrid1TopLeftChanged(Sender: TObject);
begin
  tgridcracker(Sender).InvalidateCol(1);
end;

procedure TForm1.gridcheckboxMouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  With Sender As TCheckbox Do
    Checked := not Checked;
end;

end.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.