Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2012-10

Checkbox value in TDrawGrid

3 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Jesus Reyes
to Leonardo M. Ramé

--- El vie 19-oct-12, Leonardo M. Ram? escribi?:

Show quoted text 9 lines
De: Leonardo M. Ram? Asunto: [Lazarus] Checkbox value in TDrawGrid A: "Lazarus mailing list" Fecha: viernes, 19 de octubre de 2012, 15:08 Hi, is there a method to set/get the value of a checkbox in a TDrawGrid, when the column's buttonStyle was declared as cbsCheclBoxColumn?.

Since r39142 DrawGrid have the events OnGetCheckboxState and OnSetCheckboxState previously available only in StringGrid.

Jesus Reyes A.

Reply by email

Leonardo M. Ramé
to Jesus Reyes
Jesus Reyes wrote 16 lines
--- El vie 19-oct-12, Leonardo M. Ram? escribi?: > De: Leonardo M. Ram? > Asunto: [Lazarus] Checkbox value in TDrawGrid > A: "Lazarus mailing list" > Fecha: viernes, 19 de octubre de 2012, 15:08 > Hi, is there a method to set/get the > value of a checkbox in a TDrawGrid, > when the column's buttonStyle was declared as > cbsCheclBoxColumn?. > Since r39142 DrawGrid have the events OnGetCheckboxState and OnSetCheckboxState previously available only in StringGrid.

Thanks, here are the steps to add CheckBoxes to a TDrawGrid:

1) Use Lazarus r39142 or newer.
2) Place a TDrawGrid on a form, and add goEditing to Options.
3) Add a column whith ButtonStyle = cbsCheckBoxColumn.
4) Add onDrawCell event, as usual.
5) Add onCheckBoxToggled, for example:

  procedure TForm1.DrawGridListCheckboxToggled(sender: TObject; aCol,
    aRow: Integer; aState: TCheckboxState);
  var
    lData: TMyList;
  begin
    if (ARow > 0) and (ACol = 0) then
    begin
      lData := FMyList[ARow - 1];
      lData.Checked := not lData.Checked;
    end;
  end;
  Here I have a list of items (FMyList) where each item has a "Checked"
  property which is setted to true or false each tiem the user clicks on
  a grid's checkbox. In the example the checkbox must be placed in the
  1st column.

6) Add an onGetCheckBoxState event:

  procedure TForm1.DrawGridListGetCheckboxState(Sender: TObject; ACol,
    ARow: Integer; var Value: TCheckboxState);
  var
    lData: TMyList;
  begin
    if ACol = 0 then
    begin
      lData := FMyList[ARow - 1];
      if lData.Checked then
        Value := cbChecked
      else
        Value := cbUnchecked;
    end;
  end;
  This event just check the status of an FMyList item and sets the param
  "Value" to cbChecked or cbUnchecked.

That's it.

Reply by email