Fórum Como receber os checks do DBCheckBox?? #347639
21/10/2007
0
Olá, estou efetuando um Borderô e neste form tenho um DBGrid e dentro dele tenho um DBCheckBox. Como faço pra pegar os ´Checks True´s´, ou seja, os que foram selecionados, e processar dentro de um BitBtn pra gerar um relatório com eles??
Desde já,
Muuuito OBrigada
Estou usando o seguinte código
procedure TFormBordero.FormCreate(Sender: TObject);
begin
DBCheckBox1.DataSource := dtsGrid;
DBCheckBox1.DataField := ´CD_CHECK´;
DBCheckBox1.Visible := False;
DBCheckBox1.Color := gridProcessaBordero.Color;
DBCheckBox1.Caption := ´´;
//explained later in the article
DBCheckBox1.ValueChecked := ´´;
DBCheckBox1.ValueUnChecked := ´´;
end;
procedure TFormBordero.gridProcessaBorderoColExit(Sender: TObject);
begin
if gridProcessaBordero.SelectedField.FieldName = DBCheckBox1.DataField then
DBCheckBox1.Visible := False
end;
procedure TFormBordero.gridProcessaBorderoDrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
const IsChecked : array[Boolean] of Integer =
(DFCS_BUTTONCHECK, DFCS_BUTTONCHECK or DFCS_CHECKED);
var
DrawState: Integer;
DrawRect: TRect;
begin
if (gdFocused in State) then
begin
if (Column.Field.FieldName = DBCheckBox1.DataField) then
begin
DBCheckBox1.Left := Rect.Left + gridProcessaBordero.Left + 2;
DBCheckBox1.Top := Rect.Top + gridProcessaBordero.top + 2;
DBCheckBox1.Width := Rect.Right - Rect.Left;
DBCheckBox1.Height := Rect.Bottom - Rect.Top;
DBCheckBox1.Visible := True;
end
end
else
begin
if (Column.Field.FieldName = DBCheckBox1.DataField) then
begin
DrawRect:=Rect;
InflateRect(DrawRect,-1,-1);
DrawState := ISChecked[Column.Field.AsBoolean];
gridProcessaBordero.Canvas.FillRect(Rect);
DrawFrameControl(gridProcessaBordero.Canvas.Handle, DrawRect,
DFC_BUTTON, DrawState);
end;
end;
end;
procedure TFormBordero.gridProcessaBorderoKeyPress(Sender: TObject;
var Key: Char);
begin
if (key = Chr(9)) then Exit;
if (gridProcessaBordero.SelectedField.FieldName = DBCheckBox1.DataField) then
begin
DBCheckBox1.SetFocus;
SendMessage(DBCheckBox1.Handle, WM_Char, word(Key), 0);
end;
end;
procedure TFormBordero.DBCheckBox1Click(Sender: TObject);
begin
if DBCheckBox1.Checked then
DBCheckBox1.Caption := DBCheckBox1.ValueChecked
else
DBCheckBox1.Caption := DBCheckBox1.ValueUnChecked;
end;
procedure TFormBordero.FormActivate(Sender: TObject);
begin
qryGrid.Close;
end;
Desde já,
Muuuito OBrigada
Estou usando o seguinte código
procedure TFormBordero.FormCreate(Sender: TObject);
begin
DBCheckBox1.DataSource := dtsGrid;
DBCheckBox1.DataField := ´CD_CHECK´;
DBCheckBox1.Visible := False;
DBCheckBox1.Color := gridProcessaBordero.Color;
DBCheckBox1.Caption := ´´;
//explained later in the article
DBCheckBox1.ValueChecked := ´´;
DBCheckBox1.ValueUnChecked := ´´;
end;
procedure TFormBordero.gridProcessaBorderoColExit(Sender: TObject);
begin
if gridProcessaBordero.SelectedField.FieldName = DBCheckBox1.DataField then
DBCheckBox1.Visible := False
end;
procedure TFormBordero.gridProcessaBorderoDrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
const IsChecked : array[Boolean] of Integer =
(DFCS_BUTTONCHECK, DFCS_BUTTONCHECK or DFCS_CHECKED);
var
DrawState: Integer;
DrawRect: TRect;
begin
if (gdFocused in State) then
begin
if (Column.Field.FieldName = DBCheckBox1.DataField) then
begin
DBCheckBox1.Left := Rect.Left + gridProcessaBordero.Left + 2;
DBCheckBox1.Top := Rect.Top + gridProcessaBordero.top + 2;
DBCheckBox1.Width := Rect.Right - Rect.Left;
DBCheckBox1.Height := Rect.Bottom - Rect.Top;
DBCheckBox1.Visible := True;
end
end
else
begin
if (Column.Field.FieldName = DBCheckBox1.DataField) then
begin
DrawRect:=Rect;
InflateRect(DrawRect,-1,-1);
DrawState := ISChecked[Column.Field.AsBoolean];
gridProcessaBordero.Canvas.FillRect(Rect);
DrawFrameControl(gridProcessaBordero.Canvas.Handle, DrawRect,
DFC_BUTTON, DrawState);
end;
end;
end;
procedure TFormBordero.gridProcessaBorderoKeyPress(Sender: TObject;
var Key: Char);
begin
if (key = Chr(9)) then Exit;
if (gridProcessaBordero.SelectedField.FieldName = DBCheckBox1.DataField) then
begin
DBCheckBox1.SetFocus;
SendMessage(DBCheckBox1.Handle, WM_Char, word(Key), 0);
end;
end;
procedure TFormBordero.DBCheckBox1Click(Sender: TObject);
begin
if DBCheckBox1.Checked then
DBCheckBox1.Caption := DBCheckBox1.ValueChecked
else
DBCheckBox1.Caption := DBCheckBox1.ValueUnChecked;
end;
procedure TFormBordero.FormActivate(Sender: TObject);
begin
qryGrid.Close;
end;
Michelle Guirra
Curtir tópico
+ 0
Responder
Posts
22/10/2007
Alexandrej
Olá, estou efetuando um Borderô e neste form tenho um DBGrid e dentro dele tenho um DBCheckBox. Como faço pra pegar os ´Checks True´s´, ou seja, os que foram selecionados, e processar dentro de um BitBtn pra gerar um relatório com eles??
Percorra seu dataset, quando vc marca um checkbox ele seta um valor em um campo, é só ver esse valor...
while not DataSet.eof do
begin
if valor then...
DataSet.next;
end;
Responder
Gostei + 0
11/11/2007
Michelle Guirra
Muito Grata Alexandre!
Acabei por tendo que tirar o check e configurar apenas a Grid para ser selecionada!
Obrigada.
bjs
Michelle Guirra :D
Acabei por tendo que tirar o check e configurar apenas a Grid para ser selecionada!
Obrigada.
bjs
Michelle Guirra :D
Responder
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)