我正在尝试将拖放功能实现到 DevExpress 网格中。我尝试的第一种方法不起作用,因为该dragdrop
方法没有受到影响。我是否必须让它由mouseDown
事件触发,或者我该如何去做。示例将不胜感激。到目前为止,我尝试的是:
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;
}
}