2012-12-14 70 views
0

我試圖在DevExpress網格中實現拖放功能。我嘗試過的第一種方法沒有奏效,因爲dragdrop方法沒有被擊中。我是否必須讓它由mouseDown事件觸發,或者我該如何去做這件事。例如,將不勝感激。我試過到目前爲止是這樣的:在DevExpress網格中拖放

private void gridFields_DragDrop(object sender, DragEventArgs e) 
{ 
    GridControl grid = sender as GridControl; 
    GridView view = grid.MainView as GridView; 
    GridHitInfo srcHitInfo = e.Data.GetData(typeof(GridHitInfo)) as GridHitInfo; 
    GridHitInfo hitInfo = view.CalcHitInfo(grid.PointToClient(new Point(e.X, e.Y))); 
    int sourceRow = srcHitInfo.RowHandle; 
    int targetRow = hitInfo.RowHandle; 
    MoveRow(sourceRow, targetRow); 
} 

private void MoveRow(int sourceRow, int targetRow) 
{ 
    if (sourceRow == targetRow || sourceRow == targetRow + 1) 
     return; 

    GridView view = gridFieldView; 
    DataRow row1 = view.GetDataRow(targetRow); 
    DataRow row2 = view.GetDataRow(targetRow + 1); 
    DataRow dragRow = view.GetDataRow(sourceRow); 
    decimal val1 = (decimal)row1[OrderFieldName]; 
    if (row2 == null) 
     dragRow[OrderFieldName] = val1 + 1; 
    else 
    { 
     decimal val2 = (decimal)row2[OrderFieldName]; 
     dragRow[OrderFieldName] = (val1 + val2)/2; 
    } 
} 
+0

你看了DevExpress支持網站嗎?如果你問DevExpress的支持,他們會很快告訴你。 –

+0

Devexpress支持的難過部分是他們只有在您獲得devexpress許可證後才能提供幫助。 –

回答

2

對不起,我想補充這只是一個評論,但SO不會讓我。

我假設你想允許用戶通過拖動它們在[WinForms]網格上下移動行。您認爲您需要設置MouseDown事件實際上是正確的。另外,你需要MouseMove事件。

試試本指南! http://tv.devexpress.com/Content/XtraGrid/XtraGridDragRowsBetweenGrids/XtraGridDragRowsBetweenGrids.pdf

如果您無法訪問它,請告訴我。

更新

嘗試這些。他們是特定於我的需求,但我認爲你應該能夠重新定位它們。

​​

希望有所幫助。

+0

我意識到,指南是專門爲能夠拖放多個網格之間。讓我爲一個例子挖掘一些舊代碼。 – Fise

0
GridHitInfo hitInfo = view.CalcHitInfo(new Point(e.X, e.Y)); 

未將對象引用設置爲對象的實例。