ListViewInsertionMark.Index 속성

정의

삽입 표시 옆에 나타나는 항목의 인덱스를 가져오거나 설정합니다.

public:
 property int Index { int get(); void set(int value); };
public int Index { get; set; }
member this.Index : int with get, set
Public Property Index As Integer

속성 값

삽입 표시 옆에 나타나는 항목의 인덱스이거나 삽입 표시가 나타나지 않는 경우 -1입니다.

예제

다음 코드 예제를 사용 하는 방법에 설명 합니다 ListView 삽입 표시 기능 및 구현 항목 끌어서 놓기 재정렬 표준을 사용 하 여 끌기 이벤트입니다. 삽입 표시의 위치에 대 한 처리기에서 업데이트 되는 Control.DragOver 이벤트입니다. 이 처리기에서 가장 가까운 항목의 중간점 마우스 포인터의 위치를 비교 하 고 결과 삽입 표시가 항목의 오른쪽 또는 왼쪽에 표시 되는지 여부를 확인 하려면 사용 됩니다.

전체 예제를 참조 하세요.를 ListViewInsertionMark 개요 항목을 참조 합니다.

// Moves the insertion mark as the item is dragged.
void myListView_DragOver( Object^ /*sender*/, DragEventArgs^ e )
{
   // Retrieve the client coordinates of the mouse pointer.
   Point targetPoint = myListView->PointToClient( Point(e->X,e->Y) );

   // Retrieve the index of the item closest to the mouse pointer.
   int targetIndex = myListView->InsertionMark->NearestIndex( targetPoint );

   // Confirm that the mouse pointer is not over the dragged item.
   if ( targetIndex > -1 )
   {
      // Determine whether the mouse pointer is to the left or
      // the right of the midpoint of the closest item and set
      // the InsertionMark.AppearsAfterItem property accordingly.
      Rectangle itemBounds = myListView->GetItemRect( targetIndex );
      if ( targetPoint.X > itemBounds.Left + (itemBounds.Width / 2) )
      {
         myListView->InsertionMark->AppearsAfterItem = true;
      }
      else
      {
         myListView->InsertionMark->AppearsAfterItem = false;
      }
   }

   // Set the location of the insertion mark. If the mouse is
   // over the dragged item, the targetIndex value is -1 and
   // the insertion mark disappears.
   myListView->InsertionMark->Index = targetIndex;
}
// Moves the insertion mark as the item is dragged.
private void myListView_DragOver(object sender, DragEventArgs e)
{
    // Retrieve the client coordinates of the mouse pointer.
    Point targetPoint = 
        myListView.PointToClient(new Point(e.X, e.Y));

    // Retrieve the index of the item closest to the mouse pointer.
    int targetIndex = myListView.InsertionMark.NearestIndex(targetPoint);

    // Confirm that the mouse pointer is not over the dragged item.
    if (targetIndex > -1) 
    {
        // Determine whether the mouse pointer is to the left or
        // the right of the midpoint of the closest item and set
        // the InsertionMark.AppearsAfterItem property accordingly.
        Rectangle itemBounds = myListView.GetItemRect(targetIndex);
        if ( targetPoint.X > itemBounds.Left + (itemBounds.Width / 2) )
        {
            myListView.InsertionMark.AppearsAfterItem = true;
        }
        else
        {
            myListView.InsertionMark.AppearsAfterItem = false;
        }
    }

    // Set the location of the insertion mark. If the mouse is
    // over the dragged item, the targetIndex value is -1 and
    // the insertion mark disappears.
    myListView.InsertionMark.Index = targetIndex;
}
' Moves the insertion mark as the item is dragged.
Private Sub myListView_DragOver(sender As Object, e As DragEventArgs)
    ' Retrieve the client coordinates of the mouse pointer.
    Dim targetPoint As Point = myListView.PointToClient(New Point(e.X, e.Y))
    
    ' Retrieve the index of the item closest to the mouse pointer.
    Dim targetIndex As Integer = _
        myListView.InsertionMark.NearestIndex(targetPoint)
    
    ' Confirm that the mouse pointer is not over the dragged item.
    If targetIndex > -1 Then
        ' Determine whether the mouse pointer is to the left or
        ' the right of the midpoint of the closest item and set
        ' the InsertionMark.AppearsAfterItem property accordingly.
        Dim itemBounds As Rectangle = myListView.GetItemRect(targetIndex)
        If targetPoint.X > itemBounds.Left + (itemBounds.Width / 2) Then
            myListView.InsertionMark.AppearsAfterItem = True
        Else
            myListView.InsertionMark.AppearsAfterItem = False
        End If
    End If
    
    ' Set the location of the insertion mark. If the mouse is
    ' over the dragged item, the targetIndex value is -1 and
    ' the insertion mark disappears.
    myListView.InsertionMark.Index = targetIndex
End Sub

설명

하는 경우 지정된 된 인덱스를 사용 하 여 항목의 왼쪽에 표시 되는 삽입 표시는 AppearsAfterItem 속성이 false고, 그렇지 않으면 항목의 오른쪽에 표시 됩니다. 끌어 온된 항목에 삽입 될 때 자동으로 삽입 표시가 사라집니다는 ListView.Items 컬렉션입니다. 제거 하려면 삽입 표시가 수동으로 예를 들어, 항목 컨트롤의 바깥쪽 끌거나 자체를 끌 때 설정의 Index 값-1입니다.

사용 된 NearestIndex 끌어서 놓기 작업에서 항목 위치를 지정할 때 마우스 포인터의 위치와 같은 지정된 된 위치에 가장 가까운 항목의 인덱스를 검색 하는 방법입니다.

적용 대상

추가 정보