Listview getItemAt이 null을 반환합니다.

피어 조르지오 미 슬리

나는 내에서 그 순서를 항목을 이동하기 위해 노력하고있어 listviewlargeImage 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;
        }
    }
}
Adamizer

겠습니까 ListView.FindNearestItem은 더 나은 당신이 달성하려고하는 것에 대해 작동?

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

TOP 리스트

  1. 1

    PrematureCloseException : 연결이 너무 일찍 닫혔습니다.

  2. 2

    MDRotatingPieChart를 회전하면 각도 대신 x / y 위치가 변경됩니다.

  3. 3

    c # 웹 사이트에서 텍스트를 복사하는 방법 (소스 코드 아님)

  4. 4

    jfreecharts에서 x 및 y 축 선을 조정하는 방법

  5. 5

    ArrayBufferLike의 typescript 정의의 깊은 의미

  6. 6

    Ionic 2 로더가 적시에 표시되지 않음

  7. 7

    복사 / 붙여 넣기 비활성화

  8. 8

    Google Play Console에서 '예기치 않은 오류가 발생했습니다. 나중에 다시 시도해주세요. (7100000)'오류를 수정하는 방법은 무엇입니까?

  9. 9

    정점 셰이더에서 카메라에서 개체까지의 XY 거리

  10. 10

    QT Designer를 사용하여 GUI에 이미지 삽입

  11. 11

    java Apache POI Word 기존 테이블 셀 스타일 및 서식이있는 행 삽입

  12. 12

    Kubernetes Horizontal Pod Autoscaler (HPA) 테스트

  13. 13

    Android Kotlin은 다른 활동에서 함수를 호출합니다.

  14. 14

    C # HttpWebRequest 기본 연결이 닫혔습니다. 전송시 예기치 않은 오류가 발생했습니다.

  15. 15

    어떻게 같은 CustomInfoWindow 다른 이벤트를 할 수 있습니다

  16. 16

    rclone으로 원격 디렉토리의 모든 파일을 삭제하는 방법은 무엇입니까?

  17. 17

    dataSnapShot.getValue () 반환 데이터베이스에 그겁니다 데이터 종료 널 (null)

  18. 18

    ORA-12557 TNS : 프로토콜 어댑터를로드 할 수 없습니다

  19. 19

    JNDI를 사용하여 Spring Boot에서 다중 데이터 소스 구성

  20. 20

    다음 컨트롤이 추가되었지만 사용할 수 없습니다.

  21. 21

    C # Asp.net 웹 API-JSON / XML 변환기 API 만들기

뜨겁다태그

보관