官方QQ:  16643506

如何在cxGrid内实现拖放

说明:
如何将记录拖放到同一网格中的其他位置?


procedure TForm1.ReorderRows(AView: TcxGridTableView; ADestRow: TcxCustomGridRecord);  

var  

I: Integer;  

ADC: TcxDBDataController;  

AOrderValue: Variant;  

AOrderColumnIndex: Integer;  

IsUpper: Boolean;  

begin  

with AView do  

begin  

   ADC := TcxDBDataController(DataController);  

   AOrderColumnIndex := TcxGridColumn(ADC.GetItemByFieldName('Order')).Index;  

   AOrderValue := ADestRow.Values[AOrderColumnIndex];  

   IsUpper := ADestRow .Index < ADC.GetRowIndexByRecordIndex(ADC.FindRecordIndexByKey(AKeys), False);  

end;  

ADestRow.Focused := True;  

SetOrderValue(ADC.DataSet, AOrderValue - Ord(not IsUpper) + 0.5);   // move dragged record 1 record lower  

ADC.LocateByKey(AKeys); // focus the dragged record in the DataSet  

SetOrderValue(ADC.DataSet, AOrderValue);  

if isUpper then  

   ADC.GotoLast  

else  

   ADC.GotoFirst;  

I := 0;  

while ADC.Values[ADC.FocusedRecordIndex, AOrderColumnIndex] <> AOrderValue do  

begin  

   SetOrderValue(ADC.DataSet, Ord(IsUpper) * ADC.RowCount - Sign(Ord(IsUpper) - 0.1) * (I + Ord(not IsUpper)));  

   Inc(I);  

   if IsUpper then  

     ADC.GotoPrev  

   else  

     ADC.GotoNext;  

end;  

end;



联系电话:
020-00000000
联系电话:
020-00000000
联系电话:
020-12345678