I'm self taught and relatively new to programming and have been battling with a TDBGrid's onMouseDown event in Delphi 7. Hopefully I'm missing something small and you masters out there will be able to enlighten me!
I have a TVirtualStringGrid and TDBGrid on my form. I want to be able to double click on a row on the DBGrid and open up a form to edit the contents of that record, but I also want to be able to drag a row from the DBGrid and drop it on a node in the TVirtualStringGrid.
Using the DragMode - dmAutomatic or dmManual - in the onDblClick or onClick events, I can either drag or double click, but not both. Using onMouseDown with DataGrid.BeginDrag(False, 5) and DragMode set to dmManual, to my understanding, I should solve my problem.
After much fighting, I tested with the following:
procedure TfrmMain.DataGridMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin if ((Button = mbLeft) and not (ssDouble in Shift)) then begin DataGrid.BeginDrag(False, 5); label2.caption := 'Mouse-Down - Left Button!'; end; if Button = mbRight then begin label2.caption := 'Mouse-Down - Right Button!'; end; if ssDouble in Shift then label2.caption := 'Mouse-Down - Double Click!'; if ssCtrl in Shift then label2.caption := 'Mouse-Down - Ctrl Button!'; end; procedure TfrmMain.DataGridMouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin label2.caption := 'Mouse up!'; end;
What happens now, is that if I click on one of the cells in the grid, I get absolutely no response until I release the button, then I get the 'Mouse up!' message.
If I click on the white space to the right of the final column of data, I get the correct mouse down message, but no mouse up message!
What am I missing?