Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'ListView1.Items.Add("whatever", 0)
Dim constr As String = "connstr"
Dim conn As New SqlConnection(constr)
Dim strSql As String = "SELECT part_no_1, part_no_2, part_no_3, internal_order_no_pv, " & _
"qty_per_operation, remaining_qty FROM gpstest " & _
"WHERE operation_priority > 16 and operation_finished IS NULL " & _
"ORDER BY requ_deliv_day_op"
conn.Open()
Dim dr As SqlDataReader
Dim cmd As New SqlCommand(strSql, conn)
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
ListView1.Columns.Add("Col1", 40, HorizontalAlignment.Center)
ListView1.Columns.Add("Col2", 60, HorizontalAlignment.Center)
ListView2.Columns.Add("Col1", 40, HorizontalAlignment.Center)
ListView2.Columns.Add("Col2", 60, HorizontalAlignment.Center)
While dr.Read
Dim li As New ListViewItem(CStr(dr.Item(0)))
li.SubItems.Add(CStr(dr.Item(1)))
ListView1.Items.Add(li)
li = Nothing
End While
conn = Nothing
cmd = Nothing
End Sub
Private Sub ListView1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseMove, ListView2.MouseMove
'First I check if a button has been pressed
If e.Button = MouseButtons.None Then
Exit Sub
End If
'Second, I need to cast the sender object as a listview object
Dim lstView As ListView
lstView = DirectCast(sender, ListView)
'Make sure at least one listview item is selected in the list
If lstView.SelectedItems.Count = 0 Then
Exit Sub
End If
'Create a variable to hold the item
Dim lstItem As ListViewItem = lstView.SelectedItems(0)
Dim dob As New DataObject
dob.SetData(DataFormats.Text, True, lstItem.Text)
'At this point, our code wait here until the dragdrop is complete
Dim effect As DragDropEffects = DragDropEffects.Copy Or DragDropEffects.Move
effect = lstView.DoDragDrop(dob, effect)
'if successful, remove the item from the original listview
If effect = DragDropEffects.Move Then
lstView.Items.Remove(lstItem)
End If
End Sub
Private Sub ListView1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListView1.DragEnter, ListView2.DragEnter
'We need to make sure the cursor changes when dragging an object
'Check if there is data present
If e.Data.GetDataPresent(DataFormats.Text, True) Then
e.Effect = e.AllowedEffect And DragDropEffects.Move
Else
e.Effect = DragDropEffects.None
End If
End Sub
Private Sub ListView1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles ListView1.DragDrop, ListView2.DragDrop
'Make sure there is some data in the dataobject clipboard before continue
If Not e.Data.GetDataPresent(DataFormats.Text, True) Then
Exit Sub
End If
e.Effect = DragDropEffects.Move
Dim lstView As ListView
lstView = DirectCast(sender, ListView)
lstView.Items.Add(e.Data.GetData(DataFormats.Text, True), 0)
End Sub
End Class