private Rectangle dragBoxFromMouseDown;
private int rowIndexFromMouseDown;
private int rowIndexOfItemUnderMouseToDrop;
private void ItemGrid_MouseMove(object sender, MouseEventArgs e)
{
if ((e.Button & MouseButtons.Left) == MouseButtons.Left)
{
if (dragBoxFromMouseDown != Rectangle.Empty &&
!dragBoxFromMouseDown.Contains(e.X, e.Y))
{
DragDropEffects dropEffect = Condition1Grid.DoDragDrop(Condition1Grid.Rows[rowIndexFromMouseDown], DragDropEffects.Move);
}
}
}
private void ItemGrid_MouseDown(object sender, MouseEventArgs e)
{
rowIndexFromMouseDown = Condition1Grid.HitTest(e.X, e.Y).RowIndex;
if (rowIndexFromMouseDown != -1)
{
Size dragSize = SystemInformation.DragSize;
dragBoxFromMouseDown = new Rectangle(new Point(e.X - (dragSize.Width / 2), e.Y - (dragSize.Height / 2)), dragSize);
}
else
dragBoxFromMouseDown = Rectangle.Empty;
}
private void ItemGrid_DragDrop(object sender, DragEventArgs e)
{
Point clientPoint = Condition1Grid.PointToClient(new Point(e.X, e.Y));
rowIndexOfItemUnderMouseToDrop = Condition1Grid.HitTest(clientPoint.X, clientPoint.Y).RowIndex;
if (e.Effect == DragDropEffects.Move)
{
Item item = ItemList[rowIndexFromMouseDown];
ItemList.RemoveAt(rowIndexFromMouseDown);
ItemList.Insert(rowIndexOfItemUnderMouseToDrop, item);
}
Condition1Grid.Rows[rowIndexOfItemUnderMouseToDrop].Selected = true; // 드래그해서 놓은 위치에 선택
}
private void ItemGrid_DragOver(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Move;
}