XDrag and Drop

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lou

    #1

    XDrag and Drop

    need to implement drag and drop facility in a listview.
    For example i have 10 listitems in my listview
    i need to drag and change the positions of listitems up and down
    -Lou


  • Shane

    #2
    Re: XDrag and Drop

    This code assumes that you have a listview named "lvw" and a button
    called "btnDelete"
    Basically, you get a list of the selected items, delete the items, then
    insert the selected items in the new position.

    Private Sub lvw_DragDrop(By Val sender As Object, ByVal e As
    System.Windows. Forms.DragEvent Args) Handles lvw.DragDrop
    Try
    Dim i As Integer
    Dim l_Point As Point = lvw.PointToClie nt(New Point(e.X,
    e.Y))
    Dim l_Item As ListViewItem = lvw.GetItemAt(l _Point.X,
    l_Point.Y)
    Dim l_Items() As ListViewItem =
    e.Data.GetData( "System.Windows .Forms.ListView Item()")
    Dim l_DropIndex As Integer = l_Item.Index

    btnDelete_Click (sender, New System.EventArg s)
    For Each l_Item In l_Items
    lvw.Items.Inser t(l_DropIndex + i, l_Items(i))
    i = i + 1
    Next
    Catch ex As Exception
    End Try
    End Sub

    Private Sub btnDelete_Click (ByVal sender As System.Object, ByVal e
    As System.EventArg s) Handles btnDelete.Click
    Dim l_Item As ListViewItem
    Dim l_SelectedCols As ListView.Select edListViewItemC ollection
    Dim i As Integer

    l_SelectedCols = lvw.SelectedIte ms
    lvw.BeginUpdate ()
    For i = l_SelectedCols. Count To 1 Step -1
    l_Item = l_SelectedCols( i - 1)
    l_Item.Remove()
    Next
    lvw.EndUpdate()
    End Sub

    Comment

    Working...