???? ID: 822483 - ????? ???????: 05 ?????? 2010 - ??????: 2.0

???? ????? ???????? ?? ?????? ???? ???? ?????-????-????? ??????????? ???? ?? ??? ????? ???

?????? ??????This article applies to a different operating system than the one you are using. Article content that may not be relevant to you is disabled.

?? ????? ??

??? ?? ??????? ???? | ??? ?? ??????? ????

?????

??? ?? ?????? ?? ??? ?????????? ????????????? ??? ?? ???? ?? Microsoft Windows ??? ??????? ???? ???? ???? ???? ?????? ?? ???? ?????? ?????????? ??? ????????? ?????

????

?? ?????? ?? ???? ?? ??????????? ????????????? ?????? ???? ???? ?????-????-????? ??????????? ???? ?? ??? ????? ????

????? ?????????

?? ?????? ?? ?? ???? ?? ??? ?? ??? ?????-????-????? ??????????? ?????? ?????.???? ??????? ??? ??? ????????? ????:
  1. ????? ??? ??????ListView1_ItemDrag????? ???????

    Microsoft Visual Basic .NET ?? Microsoft Visual Basic 2005 ???
     'Begins a drag-and-drop operation in the ListView control.
    ListView1.DoDragDrop(ListView1.SelectedItems, DragDropEffects.Move)
    Microsoft Visual C# .NET ?? Microsoft Visual C# 2005 ???
    //Begins a drag-and-drop operation in the ListView control.
    listView1.DoDragDrop(listView1.SelectedItems, DragDropEffects.Move);
  2. ????? ??? ??????ListView1_DragEnter????? ???????

    Visual Basic .NET ?? Visual Basic 2005 ???
    Dim i As Integer
    For i = 0 To e.Data.GetFormats().Length - 1
    If e.Data.GetFormats()(i).Equals("System.Windows.Forms.ListView+SelectedListViewItemCollection") Then
        'The data from the drag source is moved to the target.
        e.Effect = DragDropEffects.Move
    End If
    Next
    C# .NET ?? Visual C# 2005 ??? ?????
    int len=e.Data.GetFormats().Length-1 ;
    int i;
    for (i = 0 ; i<=len ;i++)
    {
        if (e.Data.GetFormats()[i].Equals("System.Windows.Forms.ListView+SelectedListViewItemCollection"))
        {
            //The data from the drag source is moved to the target.	
            e.Effect = DragDropEffects.Move;
        }
    }
    
  3. ????? ??? ??????ListView1_DragDrop????? ???????

    Visual Basic .NET ?? Visual Basic 2005 ???
    'Return if the items are not selected in the ListView control.
    If ListView1.SelectedItems.Count = 0 Then Return
    'Returns the location of the mouse pointer in the ListView control.
    Dim p As Point = ListView1.PointToClient(New Point(e.X, e.Y))
    'Obtain the item that is located at the specified location of the mouse pointer.
    Dim dragToItem As ListViewItem = ListView1.GetItemAt(p.X, p.Y)
    If dragToItem Is Nothing Then Return
    'Obtain the index of the item at the mouse pointer.
    Dim dragIndex As Integer = dragToItem.Index
    Dim i As Integer
    Dim sel(ListView1.SelectedItems.Count) As ListViewItem
    For i = 0 To ListView1.SelectedItems.Count - 1
        sel(i) = ListView1.SelectedItems.Item(i)
    Next
    For i = 0 To ListView1.SelectedItems.Count - 1
        'Obtain the ListViewItem to be dragged to the target location.
        Dim dragItem As ListViewItem = sel(i)
        Dim itemIndex As Integer = dragIndex
        If itemIndex = dragItem.Index Then Return
        If dragItem.Index < itemIndex Then
           itemIndex = itemIndex + 1
        Else
           itemIndex = dragIndex + i
        End If
        'Insert the item in the specified location.
        Dim insertitem As ListViewItem = dragItem.Clone
        ListView1.Items.Insert(itemIndex, insertitem)
        'Removes the item from the initial location while 
        'the item is moved to the new location.
        ListView1.Items.Remove(dragItem)
    Next
    
    C# .NET ?? Visual C# 2005 ??? ?????
    //Return if the items are not selected in the ListView control.
    if(listView1.SelectedItems.Count==0)
    {
       return;
    }
    //Returns the location of the mouse pointer in the ListView control.
    Point cp = listView1.PointToClient(new Point(e.X, e.Y));
    //Obtain the item that is located at the specified location of the mouse pointer.
    ListViewItem dragToItem = listView1.GetItemAt(cp.X, cp.Y);
    if(dragToItem==null)
    {
        return;
    } 
    //Obtain the index of the item at the mouse pointer.
    int dragIndex = dragToItem.Index;
    ListViewItem[] sel=new ListViewItem [listView1.SelectedItems.Count];
    for(int i=0; i<=listView1.SelectedItems.Count-1;i++)
    {
         sel[i]=listView1.SelectedItems[i];
    }
    for(int i=0; i<sel.GetLength(0);i++)
    { 
        //Obtain the ListViewItem to be dragged to the target location.
        ListViewItem dragItem = sel[i];
        int itemIndex = dragIndex;
        if(itemIndex==dragItem.Index)
       {
            return;
       }
       if(dragItem.Index<itemIndex)
           itemIndex++;
      else
           itemIndex=dragIndex+i;
       //Insert the item at the mouse pointer.
       ListViewItem insertItem = (ListViewItem)dragItem.Clone();
       listView1.Items.Insert(itemIndex, insertItem);
       //Removes the item from the initial location while 
       //the item is moved to the new location.
       listView1.Items.Remove(dragItem);
    }
    
  4. ????? ????????????? ??,??????? ??????.
  5. ????? ???????? ???????? ??,???????.

??????

?? ??????? ??????? ?????? ??..

???? ???????

??????? ?? ???: ??????? ???? ?? ??? ???

  1. Microsoft Visual Studio .NET ?? Microsoft Visual Studio 2005 ??????? ?????
  2. ????? ??? .NET, Visual Basic 2005, ????? C# 2005 ?? Visual C# .NET ?? ????? ?? ?? ??? Windows ????????? ?? ??????

    ???????? ??? ??, Form1 ??? ???? ???? ??..
  3. ????????? ?????Form1 ????????? ?????
  4. ????-????? ????ListView1?? ????-????? ????, ?? ???? ??????.
  5. ????????????? ????? ???, ????? ???????????, ?? ???? ??? ellipsis ??? (????? ????...).
  6. ?????ListViewItem ?????? ??????????? ????? ???, ????? ????add??? ????
  7. ??? ??????????? ?? ???ListViewItem???? ?? ??? ????????Item1, ??? ???????????? ?? ???ListViewItem???? ?? ??? ????????Item2, ??? ???????????? ?? ???ListViewItem???? ?? ??? ????????Item3, ?? ???? ??? ??? ??????????? ?? ???ListViewItem???? ?? ??? ????????Item4.
  8. ?????ListViewItem ?????? ??????????? ????? ???, ????? ????OK.
  9. ????????????? ????? ??ListView1, ??? ????????????? ?? ??? ???????.
  10. ??? ????AllowDrop?? ???ListView1???? ?? ???True.
  11. ????? ????????????? ??,??????? ??????.
  12. ????? ???????? ???????? ??,???????.
  13. ?????? ???? ?? ?????? ????Item1??? ???? ?? ????? ?? ??????? ????????????? ???

    ?????? ???? ?? ????Item1.

??????

???? ??????? ?? ???, ????? Microsoft ??? ?????? ?? ????::
Control.DoDragDrop ????
(vs.71) http://msdn2.Microsoft.com/en-us/library/SYSTEM.Windows.forms.control.dodragdrop .aspx (http://msdn2.microsoft.com/en-us/library/system.windows.forms.control.dodragdrop(vs.71).aspx)
Control.DragDrop ?????
(vs.71) http://msdn2.Microsoft.com/en-us/library/SYSTEM.Windows.forms.control.dragdrop .aspx (http://msdn2.microsoft.com/en-us/library/system.windows.forms.control.dragdrop(vs.71).aspx)
???????? ??????? ?? ???, Microsoft ?????? ??? ??? ???? ????? ?? ??? ????? ???? ?????? ????? ????::
822482  (http://support.microsoft.com/kb/822482/ ) TO HOW: Microsoft Visual Basic .NET ?? ????? ?? Microsoft Windows ??????????? ??? ??????-??-????? ??????????? ?????? ?????


???? ???? ???? ??:
  • Microsoft Visual Basic 2005
  • Microsoft Visual Basic .NET 2003 Standard Edition
  • Microsoft Visual Basic .NET 2002 Standard Edition
  • Microsoft Visual C# 2005 Express Edition
  • Microsoft Visual C# .NET 2003 Standard Edition
  • Microsoft Visual C# .NET 2002 Standard Edition
??????: 
kbvs2005swept kbvs2005applies kbforms kbwindowsforms kblistview kbdragdrop kbctrl kbcontrol kbprb kbmt KB822483 KbMthi
???? ?????? ???????????? ?????? ????????
??????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??:822483  (http://support.microsoft.com/kb/822483/en-us/ )