나는 내에서 그 순서를 항목을 이동하기 위해 노력하고있어 listview
와 largeImage style.
문제점하는 것은 존재 getItemAt(x, y)
메소드 내부에 dragdrop
이 방법이 항상 반환 널 (null) 때문에 (가) 경우에만 dragDrop
기존 항목을 통해 정확하게 수행되지 않습니다 ( 보통 내가 두 항목 사이에 드롭, 그것은 더 직관적이다 imo ).
private void lvPictures_DragDrop(object sender, DragEventArgs e)
{
Point p = lvPictures.PointToClient(new Point(e.X, e.Y));
ListViewItem MovetoNewPosition = lvPictures.GetItemAt(p.X, p.Y);
//MovetoNewPosition is null
}
요점은 dragDrop
두 항목 사이에서 수행 되는 가장 가까운 항목을 가져 오는 방법입니다 .
대답은 저를 올바른 방향으로 안내했습니다. 이것이 "가장 가까운 찾기"방법을 구현 한 방법입니다. (완벽하지는 않지만 지금은 작동합니다)
ListViewItem itemToBeMoved = (e.Data.GetData(typeof(ListView.SelectedListViewItemCollection)) as ListView.SelectedListViewItemCollection)[0];
ListViewItem itemToBeMovedClone = (ListViewItem)itemToBeMoved.Clone();
ListViewItem itemInDropPosition = listView.GetItemAt(p.X, p.Y);
if (itemInDropPosition == null)
{
ListViewItem leftItem = listView.FindNearestItem(SearchDirectionHint.Left, p);
ListViewItem rightItem = listView.FindNearestItem(SearchDirectionHint.Right, p);
if (leftItem == null && rightItem == null)
{
return;
}
else if (leftItem == null)
{
itemInDropPosition = rightItem;
}
else if (rightItem == null)
{
itemInDropPosition = leftItem;
}
else
{
//PGM: appens that if you move to the right or to the left, between two items, the left item (if moving to the right) or the right item (if moving to the left) is wrong, because it select not the first one, but the second
if (rightItem.Index - leftItem.Index > 1 && leftItem.Index < itemToBeMoved.Index && rightItem.Index <= itemToBeMoved.Index)
{
//we are moving to the left
rightItem = listView.Items[rightItem.Index - 1];
}
else if (rightItem.Index - leftItem.Index > 1 && leftItem.Index >= itemToBeMoved.Index && rightItem.Index > itemToBeMoved.Index)
{
//we are moving to the right
leftItem = listView.Items[leftItem.Index + 1];
}
else if (rightItem.Index - leftItem.Index > 1)
{
//significa che è stato spostato sul posto e non va mosso
return;
}
if (Math.Abs(p.X - leftItem.Position.X) < Math.Abs(p.X - rightItem.Position.X))
{
itemInDropPosition = leftItem;
}
else
{
itemInDropPosition = rightItem;
}
}
}
겠습니까 ListView.FindNearestItem은 더 나은 당신이 달성하려고하는 것에 대해 작동?
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다