Delphi FAQ -

| | | | | |
| | | | | | |



Google  
 

CheckBox DBGrid




Bpa eae oo, payc y o copae, pocae eee, oo oe ooo ooo cpaae ecpy:
- a ooo?
- Boc, oo ceac ocy.
- oeco?
- eoco .
- oe?
- poece aca caoc ya. e ye e?
- Mopo.


procedure DrawGridCheckBox(Canvas: TCanvas; Rect: TRect; Checked: boolean);
var
  DrawFlags: Integer;
begin
  Canvas.TextRect(Rect, Rect.Left + 1, Rect.Top + 1, ' ');
  DrawFrameControl(Canvas.Handle, Rect, DFC_BUTTON, DFCS_BUTTONPUSH or DFCS_ADJUSTRECT);
  DrawFlags := DFCS_BUTTONCHECK or DFCS_ADJUSTRECT;// DFCS_BUTTONCHECK
  if Checked then
    DrawFlags := DrawFlags or DFCS_CHECKED;
  DrawFrameControl(Canvas.Handle, Rect, DFC_BUTTON, DrawFlags);
end;

OnDrawColumnCell DrawGridCheckBox():


procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject; const Rect: TRect;
  DataCol: Integer; Column: TColumn; State: TGridDrawState);
begin
  if Column.FieldName = 'WEIGHT' then //   
    if Column.Field.AsInteger > 10 then
      DrawGridCheckBox(DBGrid1.Canvas, Rect, true)
    else
      DrawGridCheckBox(DBGrid1.Canvas, Rect, false)
end;

, CheckBox- OnColumnEnter:


procedure TfrmMain.DBGrid1ColEnter(Sender: TObject);
begin
  with TDBGrid(Sender) do
    if SelectedField.FieldName = 'Weight' then //   
      Options := Options - [dgEditing]
    else
      Options := Options + [dgEditing]
end;






Copyright 2004-2016 "Delphi Sources". Delphi World FAQ




     Twitter     Facebook