Avatar of yarek
yarek
Flag for France asked on

delphi6 DBGRID component with checkbox

OI need a FREE delphi6 DBGrid COMPONENT with Checkbox feature.

ANy source ?
Delphi

Avatar of undefined
Last Comment
mahdiparak

8/22/2022 - Mon
TName

yarek

ASKER
COMPONENTS in UPPERCASE, no CODE SOURCE
ASKER CERTIFIED SOLUTION
sun4sunday

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
mahdiparak

use this

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, DB, DBTables, Grids, DBGrids;

type
  TForm1 = class(TForm)
    DBGrid1: TDBGrid;
    Table1: TTable;
    DataSource1: TDataSource;
    procedure DBGrid1CellClick(Column: TColumn);
    procedure DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    procedure DBGrid1ColEnter(Sender: TObject);
    procedure DBGrid1ColExit(Sender: TObject);
  private

 FOriginalOptions : TDBGridOptions; { Private declarations }
  public
   procedure SaveBoolean;
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.SaveBoolean;
begin
 Self.DBGrid1.SelectedField.Dataset.Edit;
 Self.DBGrid1.SelectedField.AsBoolean := not Self.DBGrid1.SelectedField.AsBoolean;
 Self.DBGrid1.SelectedField.Dataset.Post;
end;

procedure TForm1.DBGrid1CellClick(Column: TColumn);
begin
 if Self.DBGrid1.SelectedField.DataType = ftBoolean then
  SaveBoolean();
end;

procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
Const
 CtrlState : array[Boolean] of Integer = (DFCS_BUTTONCHECK,
     DFCS_BUTTONCHECK or DFCS_CHECKED);
var
 CheckBoxRectangle : TRect;
begin
 if Column.Field.DataType = ftBoolean then
 begin
 Self.DBGrid1.Canvas.FillRect(Rect);
 CheckBoxRectangle.Left := Rect.Left + 2;
 CheckBoxRectangle.Right := Rect.Right - 2;
 CheckBoxRectangle.Top := Rect.Top + 2;
 CheckBoxRectangle.Bottom := Rect.Bottom - 2;
 DrawFrameControl(Self.DBGrid1.Canvas.Handle,
      CheckBoxRectangle,
      DFC_BUTTON,
      CtrlState[Column.Field.AsBoolean]);
 end;
end;
procedure TForm1.DBGrid1ColEnter(Sender: TObject);
begin
 if Self.DBGrid1.SelectedField.DataType = ftBoolean then
 begin
  Self.FOriginalOptions := Self.DBGrid1.Options;
  Self.DBGrid1.Options := Self.DBGrid1.Options - [dgEditing];
 end;
end;

procedure TForm1.DBGrid1ColExit(Sender: TObject);
begin
 if Self.DBGrid1.SelectedField.DataType = ftBoolean then
  Self.DBGrid1.Options := Self.FOriginalOptions;
end;

end.


=====================================================================================================


use this for form :

object Form1: TForm1
  Left = 192
  Top = 114
  Width = 870
  Height = 640
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object DBGrid1: TDBGrid
    Left = 0
    Top = 0
    Width = 862
    Height = 606
    Align = alClient
    DataSource = DataSource1
    TabOrder = 0
    TitleFont.Charset = DEFAULT_CHARSET
    TitleFont.Color = clWindowText
    TitleFont.Height = -11
    TitleFont.Name = 'MS Sans Serif'
    TitleFont.Style = []
    OnCellClick = DBGrid1CellClick
    OnColEnter = DBGrid1ColEnter
    OnColExit = DBGrid1ColExit
    OnDrawColumnCell = DBGrid1DrawColumnCell
  end
  object Table1: TTable
    Active = True
    DatabaseName = 'DBDEMOS'
    TableName = 'reservat.db'
    Left = 128
    Top = 88
  end
  object DataSource1: TDataSource
    DataSet = Table1
    Left = 176
    Top = 80
  end
end
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes