DbGrid Nesnesine CheckBox ekleme

Delphi'de kod yazma ile ilgili sorularınızı bu foruma yazabilirsiniz.
Cevapla
smokie
Üye
Mesajlar: 72
Kayıt: 01 Tem 2007 10:26

DbGrid Nesnesine CheckBox ekleme

Mesaj gönderen smokie »

Arkadaşlar mrhb...

konuya yazdıgım şekilde aradım var olan
önekleri uygulayamadım.

procedure TForm1.DBGrid1DrawColumnCell(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 + DBGrid1.Left + 2;
DBCheckBox1.Top := Rect.Top + DBGrid1.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];
DBGrid1.Canvas.FillRect(Rect);
DrawFrameControl(DBGrid1.Canvas.Handle, DrawRect,DFC_BUTTON, DrawState);
end;
end;
end;

procedure TForm1.DBGrid1ColExit(Sender: TObject);
begin
if DBGrid1.SelectedField.FieldName = DBCheckBox1.DataField then
DBCheckBox1.Visible := False
end;

procedure TForm1.DBGrid1KeyPress(Sender: TObject; var Key: Char);
begin
if (key = Chr(9)) then Exit;
if (DBGrid1.SelectedField.FieldName = DBCheckBox1.DataField) then
begin
DBCheckBox1.SetFocus;
SendMessage(DBCheckBox1.Handle, WM_Char, word(Key), 0);
end;
end;

procedure TForm1.DBCheckBox1Click(Sender: TObject);
begin
if DBCheckBox1.Checked then DBCheckBox1.Caption := DBCheckBox1.ValueChecked
else DBCheckBox1.Caption := DBCheckBox1.ValueUnChecked;
end;
-------------------------

1. Forma bir TcheckBox bileşeni koyun ve visible'ını False yap. Verdiğim kodda TcheckBox'ın ismi : Dbck
2. DBGrid1DrawColumnCell olayını aşağıdaki gibi ayarlayın.
3. DBGrid1ColExit olayını aşağıdaki gibi ayarlayın.
4. DBCheck.Click olayını aşağıdaki gibi ayarlayın.



procedure Tform1.DBGrid1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin

If (gdFocused in State) then
begin
// EXPRECORD is the name of the field to apply checkbox to
If(Uppercase(Trim(Column.FieldName)) = 'EXPRECORD' ) Then
begin
DBCk.Visible:=True;
DBCk.SetBounds(Rect.Left + DBGrid1.Left + 1,
Rect.Top + DBGrid1.Top + 1,
Rect.Right -Rect.Left,
Rect.Bottom - Rect.Top);
DBCk.Checked:=TBWorkingExpRecord.Value;
end;
end;


procedure Tform1.DBGrid1ColExit(Sender: TObject);
begin
DBCk.Visible:=False;
end;

procedure Tform1.DBCkClick(Sender: TObject);
begin
// Set field value in table equivalent to the check
// We used TCheckbox instead of TDBCheckbox due to null
// value handling
Try
TBWorking.Edit;
TBWorkingExpRecord.Value:=DBCk.Checked;
TBWorking.Post;
Except
On E:EDatabaseError do Showmessage(E.Message);
End;
end;
F.Atagun
Üye
Mesajlar: 158
Kayıt: 01 Oca 2008 01:56

Re: DbGrid Nesnesine CheckBox ekleme

Mesaj gönderen F.Atagun »

Merhaba,

Hocam bu konuda birçok güzel bileşen bulunmaktadır.
Checbox yanında bir sürü özelliği olan bir güzel bir bileşen seti.

İncelemeni öneririm

http://www.bergsoft.net/




Kolay gelsin
shadowmann
Üye
Mesajlar: 508
Kayıt: 30 Oca 2004 10:49

Re: DbGrid Nesnesine CheckBox ekleme

Mesaj gönderen shadowmann »

About delphiden. Bu çalışıyor. Benim önerim jedi içindeki ultimdbgrid' i kullanmanız.

Kod: Tümünü seç

procedure TForm1.FormCreate(Sender: TObject);
begin
 DBCheckBox1.DataSource := DataSource1;
 DBCheckBox1.DataField  := 'Winner';
 DBCheckBox1.Visible    := False;
 DBCheckBox1.Color      := DBGrid1.Color;
 DBCheckBox1.Caption    := '';
 
 //explained later in the article
 DBCheckBox1.ValueChecked := 'Yes a Winner!'; 
 DBCheckBox1.ValueUnChecked := 'Not this time.'; 
end;

Kod: Tümünü seç

procedure TForm1.DBGrid1DrawColumnCell(
  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 + DBGrid1.Left + 2;
     DBCheckBox1.Top := Rect.Top + DBGrid1.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];

      DBGrid1.Canvas.FillRect(Rect);
      DrawFrameControl(DBGrid1.Canvas.Handle, DrawRect, 
                       DFC_BUTTON, DrawState);
    end;
  end; 
end;

Kod: Tümünü seç

procedure TForm1.DBGrid1ColExit(Sender: TObject);
begin
  if DBGrid1.SelectedField.FieldName = DBCheckBox1.DataField then 
    DBCheckBox1.Visible := False
end;
procedure TForm1.DBGrid1KeyPress(Sender: TObject; var Key: Char);
begin
  if (key = Chr(9)) then Exit;

  if (DBGrid1.SelectedField.FieldName = DBCheckBox1.DataField) then
  begin
    DBCheckBox1.SetFocus;
    SendMessage(DBCheckBox1.Handle, WM_Char, word(Key), 0);
  end;
end;
procedure TForm1.DBCheckBox1Click(Sender: TObject);
begin
  if DBCheckBox1.Checked then
     DBCheckBox1.Caption := DBCheckBox1.ValueChecked
  else
     DBCheckBox1.Caption := DBCheckBox1.ValueUnChecked;
end;
Her zaman bir vâmuk-i azra olur alem bu ya,
Nev-be-nev efsaneler peydâ olur alem bu ya,
Kabz u bast kıl tefekkür aleminde ey gönül,
Vakt-i sermânın sonu, vakt-i germân olur alem bu ya...
smokie
Üye
Mesajlar: 72
Kayıt: 01 Tem 2007 10:26

Re: DbGrid Nesnesine CheckBox ekleme

Mesaj gönderen smokie »

yarımlarınız için tşkler
Caylaq yazdı:Merhaba,

Hocam bu konuda birçok güzel bileşen bulunmaktadır.
Checbox yanında bir sürü özelliği olan bir güzel bir bileşen seti.

İncelemeni öneririm

http://www.bergsoft.net/




Kolay gelsin

tam istediğim gibi tşkler
shadowmann
Üye
Mesajlar: 508
Kayıt: 30 Oca 2004 10:49

Re: DbGrid Nesnesine CheckBox ekleme

Mesaj gönderen shadowmann »

Aslında bu konuda ücretli vs bileşen yerine jedi deki ultimdbgrid kullanılabilir.
Her zaman bir vâmuk-i azra olur alem bu ya,
Nev-be-nev efsaneler peydâ olur alem bu ya,
Kabz u bast kıl tefekkür aleminde ey gönül,
Vakt-i sermânın sonu, vakt-i germân olur alem bu ya...
Cevapla