Link to home
Start Free TrialLog in
Avatar of klompen
klompen

asked on

CheckBox in StringGrid

Hi,

Is there any good (preferebly free) TStringGrid component that you can have CheckBox type column?

I know that TMS software has one, but I dont like it because it needs "gdiplus.dll" which sometimes does not exist.

JEDI VCL TJvStringGrid does not have this feature :(

So, anyone know or have the code and willing to share?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Limbeck
Limbeck

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MerijnB
does it have to be a stringgrid, or something which can display data as a grid?

if so, take a look at VirtualStringTree: http://www.delphi-gems.com/index.php?option=com_content&task=view&id=12&Itemid=38
i think this is the basic in implimentation of check box in stringgrid

Unit1. dfm
=========

object Form1: TForm1
  Left = 250
  Top = 229
  Width = 253
  Height = 208
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  OnCreate = FormCreate
  PixelsPerInch = 96
  TextHeight = 13
  object StringGrid1: TStringGrid
    Left = 0
    Top = 0
    Width = 233
    Height = 161
    ColCount = 3
    TabOrder = 0
    OnDrawCell = StringGrid1DrawCell
    RowHeights = (
      24
      24
      24
      24
      24)
  end
end


Unit1.pas
========

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, Grids;

type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    procedure FormCreate(Sender: TObject);
    procedure StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
      Rect: TRect; State: TGridDrawState);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var i:Integer;
begin
   for i:=1 to 4 do
   begin
     StringGrid1.Cells[0,i]:=IntToStr(i);
     if i mod 2=0 then
       StringGrid1.Cells[1,i]:='True'
     else StringGrid1.Cells[1,i]:='False';
   end;
end;

procedure TForm1.StringGrid1DrawCell(Sender: TObject; ACol, ARow: Integer;
  Rect: TRect; State: TGridDrawState);
begin

   if (ARow>0) and (ACol=2) then
   begin
     StringGrid1.Canvas.FillRect(Rect);
     if SameText(StringGrid1.Cells[ACol-1, ARow],'True') then
       DrawFrameControl(StringGrid1.Canvas.Handle, Rect, DFC_BUTTON, DFCS_BUTTONCHECK or DFCS_CHECKED)
     else DrawFrameControl(StringGrid1.Canvas.Handle, Rect, DFC_BUTTON, DFCS_BUTTONCHECK)
   end
   else StringGrid1.Canvas.TextRect(Rect, Rect.Left+2, Rect.Top+2, StringGrid1.Cells[ACol, ARow]);
end;

end.
Avatar of klompen
klompen

ASKER

Thanks
glad to be of help. :)

Ed