Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   insertar un Tchebox en un TDBGrid (https://www.clubdelphi.com/foros/showthread.php?t=50342)

mjjj 15-11-2007 01:16:33

insertar un Tchebox en un TDBGrid
 
hola amigos... necesito hacer lo siguiente, no se si se podra....

necesito mostrar ciertos datos en un grid para que el usuario decida cual o cuales de ellos se van a escoger...
lo que pretendo es hacer que en una celda de cada fila se coloque un checkbox

es decir.... insertar un checkbox dentro de un grid...

se puede hacer eso... existe un componente asi??

de antemano muchas gracias a todos.....

johan 15-11-2007 01:22:23

Hola,
algo hay, mirate esta pagina a ver si te ayuda:

http://delphi.about.com/od/usedbvcl/l/aa082003a.htm


un saludo

JOAN

Neftali [Germán.Estévez] 15-11-2007 11:22:35

Una búsqueda en los foros antes de preguntar también te dará múltiples resultados, es un tema recurrente que ya hemos tratado otras veces...

zurdosoft 21-11-2007 19:39:44

Checkbox en DbGrid
 
(Acentos omitidos a proposito)
Neftali tiene razon, el tema se ha tratado varias veces. He probado mucha soluciones y ninguna funciona perfectamente.
Esto lo encontré en la web y es del año 2002 pero es excelente.
Para probarlo puse una DbGrid y un ClientDataSet, cree los campos SEL(boolean) Y DESCRIPCION(string). Luego CreateDataSet y ejecute.
La primera vez por supuesto salta el error de que no halla el archivo 'base'.
Cargue algunos datos en Descripcion y Cerre.
Volvi a abrir y PERFECTO.
Espero que les sirva, es mas de lo mismo pero anda.
Felices Fiestas.

Código Delphi [-]
unit Ubase;

// Articulo Original
// http://www.planet-source-code.com/vb...d=779&lngWId=7
// Modificado por zurdosoft@aol.com

interface

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

type
  TForm1 = class(TForm)
    cds: TClientDataSet;
    ds: TDataSource;
    DBGrid: TDBGrid;
    cdssel: TBooleanField;
    cdsDescripcion: TStringField;
    cdsPrecio: TCurrencyField;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure DBGridCellClick(Column: TColumn);
    procedure DBGridDrawColumnCell(Sender: TObject; const Rect: TRect;
      DataCol: Integer; Column: TColumn; State: TGridDrawState);
    procedure DBGridColEnter(Sender: TObject);
    procedure DBGridColExit(Sender: TObject);
  private
    { Private declarations }
    FOriginalOptions : TDBGridOptions;
    procedure SaveBoolean;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  cds.LoadFromFile('base');
  Self.FOriginalOptions:= Self.DBGrid.Options;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  cds.SaveToFile('base');
end;

procedure TForm1.DBGridCellClick(Column: TColumn);
begin
  if Self.DBGrid.SelectedField.DataType = ftBoolean then
    SaveBoolean();
end;
// SAVEBOOLEAN
procedure TForm1.SaveBoolean;
begin
 Self.DBGrid.SelectedField.Dataset.Edit;
 Self.DBGrid.SelectedField.AsBoolean := not Self.DBGrid.SelectedField.AsBoolean;
 Self.DBGrid.SelectedField.Dataset.Post;
end;


procedure TForm1.DBGridDrawColumnCell(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.DBGrid.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.DBGrid.Canvas.Handle,
                      CheckBoxRectangle,
                      DFC_BUTTON,
                      CtrlState[Column.Field.AsBoolean]);
   end;
end;

procedure TForm1.DBGridColEnter(Sender: TObject);
begin
  if Self.DBGrid.SelectedField.DataType = ftBoolean then
    begin
      Self.FOriginalOptions := Self.DBGrid.Options;
      Self.DBGrid.Options := Self.DBGrid.Options - [dgEditing];
    end;
end;

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

end.


La franja horaria es GMT +2. Ahora son las 13:46:05.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi