Search code examples
delphicheckboxdelphi-7dbgrid

Delphi - dbGrid Select All


I put on a TwwdbGrid a checkbox field to select the record, I'd like to know if it's possible to put a checkbox on the label of the field on the grid and when the user click on it, it's select all the fields, anyone knows how to do that???

Example

Thanks in advance


Solution

  • The only way I can think of doing it is to use a TImageList and override DoCalcTitleImage. Heres a stripped down version where I have subclassed the grid and added support for various images on the columns.

    procedure TRGDBGrid.DoCalcTitleImage(Sender: TObject; Field: TField;
      var TitleImageAttributes: TwwTitleImageAttributes);
    
    begin
      inherited;
      { Get Image Number }
      lAttr := Attribute_Of_Field;
      TitleImageAttributes.ImageIndex := ord(lAttr);
    end;
    

    You can use two images - an unchecked and a check checkbox. And you need to use OnTitleClick event to handle it.