1. 程式人生 > >Delphi DBGrid記錄全選和反選拖動處理

Delphi DBGrid記錄全選和反選拖動處理

aso -- control 全選和反選 end ram list not set

DBGrid1.DragMode := dmManual;//留意這個設置不要變

procedure ApplicationEvents1Message(var Msg: tagMSG; var Handled: Boolean);

procedure TForm18.ApplicationEvents1Message(var Msg: tagMSG;
var Handled: Boolean);
begin
case Msg.message of
WM_LBUTTONDOWN:
begin
if Msg.hwnd = DBGrid1.Handle then
begin
DBGrid1.Perform(Msg.message, Msg.wParam, Msg.lParam);
DBGrid1.DragMode := dmAutomatic;
end;
end;
WM_LBUTTONUP: DBGrid1.DragMode := dmManual;
end;
end;

---------------------------------------------------------------

procedure TForm10.SpeedButton7Click(Sender: TObject);

//全選

begin
with DBGrid1.datasource.dataset do
begin
First;
while not dm.AQ_personal.EOF do
begin
DBGrid1.SelectedRows.CurrentRowSelected := True;
dm.AQ_personal.Next;
end;
end;
end;

procedure TForm10.SpeedButton8Click(Sender: TObject);//反選
var
i:integer;
SavePlace:TBookmarkList;
begin
DBGrid1.DataSource.DataSet.DisableControls;
for i:=1 to DBGrid1.DataSource.DataSet.RecordCount do
begin
DBGrid1.DataSource.DataSet.RecNo:=i;
DBGrid1.SelectedRows.CurrentRowSelected:=Not DBGrid1.SelectedRows.CurrentRowSelected;
end;
SavePlace:=DBGrid1.SelectedRows;
// DBGrid1.DataSource.DataSet.GotoBookmark(Pointer(SavePlace[0]));//將指針指向當前選擇的第一條記錄
DBgrid1.DataSource.DataSet.EnableControls;
end;

Delphi DBGrid記錄全選和反選拖動處理