您好,如同您所说,当试图拖动一列到有merge cell的区域时,因为拖动操作不能成功执行,所以无法触发fpSpread1_ColumnDragMoveCompleted事件,故无法得知用户到底拖动到第几列。
以下代码能够得到用户试图拖动到第几列:
public partial class Form1 : Form
{
bool isColumnDragMove = false;
int moveFromColumnIndex;
int moveToColumnIndex;
public Form1()
{
InitializeComponent();
this.fpSpread1.ColumnDragMove += fpSpread1_ColumnDragMove;
this.fpSpread1.MouseUp += fpSpread1_MouseUp;
}
void fpSpread1_MouseUp(object sender, MouseEventArgs e)
{
if (isColumnDragMove)
{
HitTestInformation hitInfo = fpSpread1.HitTest(e.X, e.Y);
if (hitInfo.Type == HitTestType.Viewport)
{
moveToColumnIndex = hitInfo.ViewportInfo.Column;
}
else if (hitInfo.Type == HitTestType.ColumnHeader)
{
moveToColumnIndex = hitInfo.HeaderInfo.Column;
}
if (moveToColumnIndex > moveFromColumnIndex) //从左向右移动
{
//移动的列试图插入到moveToColumnIndex之后
//写自己的处理代码
}
else//从右向左移动
{
//移动的列试图插入到moveToColumnIndex之前
//写自己的处理代码
}
isColumnDragMove = false;
}
}
void fpSpread1_ColumnDragMove(object sender, FarPoint.Win.Spread.DragMoveEventArgs e)
{
isColumnDragMove = true;
moveFromColumnIndex = e.Index;
}
}
请试之。 |