'How do I drag and drop from a TDBGrid?

If I set DragMode to dmAutomatic it prevents me from selecting rows. If I used OnCellClick to call BeginDrag it only fires on mouse up, which is not dragging in my opinion. If I use OnMouseDown it only fires on title row.

How I am I supposed do it?



Solution 1:[1]

Overloading MouseDown will lead to the desired result.

type
  TDBGrid=Class(DBGrids.TDBGrid)
         procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
  End;


  TForm2 = class(TForm)
    .......
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

{ TDBGrid }

procedure TDBGrid.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  Begindrag(false);
  inherited;
end;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 bummi