//实现鼠标拖动多选,必须设置
//cxGrdDataTV.DragMode=dmAutomatic
//cxGrdDataTV.OptionsSelection.MultiSelect=True
procedure TfrmBase_DB_SingleGrid.cxGrdDataTVDragOver(Sender, Source: TObject; X,
Y: Integer; State: TDragState; var Accept: Boolean);
procedure SwapInt(var A, B: integer);
var
tmp: Integer;
begin
tmp := a;
a := b;
b := tmp;
end;
var
AHitTest: TcxCustomGridHitTest;
i, IndexStart, IndexEnd: integer;
begin
if cxGrdDataTV.DragMode <> dmAutomatic then
Exit;
if cxGrdDataTV.OptionsSelection.MultiSelect = False then
Exit;
cxGrdDataTV.BeginUpdate;
AHitTest := cxGrdDataTV.ViewInfo.GetHitTest(X, Y);
if AHitTest is TcxGridRecordHitTest then
begin
IndexStart := cxGrdDataTV.Controller.FocusedRecord.Index;
IndexEnd := TcxGridRecordHitTest(AHitTest).GridRecord.Index;
cxGrdDataTV.Controller.ClearSelection;
if IndexEnd < IndexStart then
SwapInt(IndexStart, IndexEnd);
for i := IndexStart to IndexEnd do
cxGrdDataTV.ViewData.Records[i].Selected := True;
end;
cxGrdDataTV.EndUpdate;
end;