Can someone help me! See attachment if needed.
Dim tblGridDragTo As New DataTable("EmployeDragTo") Private lastMouseDown As Nullable(Of Point)
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load lastMouseDown = Nothing
'********************************************** 'winListView - DragFrom '**********************************************UltraListView1.AllowDrop = True UltraListView1.ItemSettings.LassoSelectMode = LassoSelectMode.LeftMouseButton UltraListView1.ItemSettings.SelectionType = SelectionType.Extended UltraListView1.View = UltraListViewStyle.Tiles UltraListView1.ViewSettingsTiles.SubItemsVisibleByDefault = True
UltraListView1.MainColumn.Key = "id" UltraListView1.MainColumn.DataType = GetType(Integer) UltraListView1.MainColumn.Text = "Number"
'Columns Dim c As UltraListViewSubItemColumn c = UltraListView1.SubItemColumns.Add("Name") c.DataType = GetType(String) c.Text = "Employe"
'Items Dim i As UltraListViewItem i = UltraListView1.Items.Add("1", "1") i.SubItems("Name").Value = "Robin Piche"
i = UltraListView1.Items.Add("2", "2") i.SubItems("Name").Value = "Daniel Jutras"
'********************************************** 'winGrid - DragTo '********************************************** tblGridDragTo.Columns.Add("Number", GetType(Integer)) tblGridDragTo.Columns.Add("NAme", GetType(String))
tblGridDragTo.Rows.Add("3", "Martin Renaud")
UltraGrid1.AllowDrop = True UltraGrid1.DataSource = tblGridDragTo End Sub
Private Sub UltraGrid1_DragOver(sender As Object, e As System.Windows.Forms.DragEventArgs) Handles UltraGrid1.DragOver e.Effect = DragDropEffects.Copy End Sub
Private Sub UltraGrid1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles UltraGrid1.DragEnter e.Effect = DragDropEffects.Copy End Sub
Private Sub UltraGrid1_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles UltraGrid1.DragDrop 'Remove the item from the current listview and drop it in the new listview With CType(sender, UltraListView) If e.Data.GetDataPresent(GetType(UltraListViewItem)) Then Dim draggedItem As UltraListViewItem = CType(e.Data.GetData(GetType(UltraListViewItem)), UltraListViewItem) MsgBox(draggedItem.Key) End If End With End Sub
Private Sub UltraListView1_DragEnter(sender As Object, e As System.Windows.Forms.DragEventArgs) Handles UltraListView1.DragEnter e.Effect = DragDropEffects.Copy End Sub
Private Sub UltraListView1_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles UltraListView1.MouseMove If Me.lastMouseDown.HasValue Then Dim dragSize As Size = SystemInformation.DragSize Dim dragRect As New Rectangle(Me.lastMouseDown.Value, dragSize) dragRect.X = CInt(dragRect.X - (dragSize.Width / 2)) dragRect.Y = CInt(dragRect.Y - (dragSize.Height / 2))
If Not dragRect.Contains(e.Location) Then Dim itemAtPoint As UltraListViewItem = UltraListView1.ItemFromPoint(e.Location) UltraGrid1.DoDragDrop(itemAtPoint, DragDropEffects.Copy) End If End If End Sub
Private Sub UltraListView1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles UltraListView1.MouseDown ' Record the cursor location If e.Button = MouseButtons.Left Then Me.lastMouseDown = e.Location Else If UltraListView1.ActiveItem IsNot Nothing Then UltraListView1.Items.Remove(UltraListView1.ActiveItem) Me.lastMouseDown = Nothing Else Me.lastMouseDown = Nothing End If End If End Sub
Thanks Mike!
Solution work well.... Here the source code i change.
Private Sub UltraListView1_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles UltraListView1.MouseMove
Dim listViewDrag As UltraListView = TryCast(sender, UltraListView)
' If the left mouse button is pressed, and the recorded cursor
' location is set to a valid value, continue...
If e.Button = Windows.Forms.MouseButtons.Left AndAlso Me.lastMouseDownLocation IsNot Nothing AndAlso listViewDrag.SelectedItems.Count > 0 Then
Dim cursorPos As New Point(e.X, e.Y)
Dim dragPoint As Point = DirectCast(Me.lastMouseDownLocation, Point)
' Determine whether the cursor has moved outside the drag rectangle;
' if it has, initiate a drag drop operation.
Dim dragRect As New Rectangle(dragPoint, SystemInformation.DragSize)
dragRect.X -= CInt((SystemInformation.DragSize.Width / 2))
dragRect.Y -= CInt((SystemInformation.DragSize.Height / 2))
If dragRect.Contains(cursorPos) = False Then
listViewDrag.Capture = False
listViewDrag.DoDragDrop(listViewDrag.SelectedItems, DragDropEffects.Copy)
End If
End Sub
Private Sub UltraGrid1_DragDrop(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles UltraGrid1.DragDrop
Dim listViewDrop As UltraListView = TryCast(sender, UltraListView)
Dim dataObject As IDataObject = e.Data
If dataObject IsNot Nothing Then
Dim selectedItems As UltraListViewSelectedItemsCollection = TryCast(dataObject.GetData(GetType(UltraListViewSelectedItemsCollection)), UltraListViewSelectedItemsCollection)
If selectedItems IsNot Nothing Then
For i As Integer = selectedItems.Count - 1 To 0 Step -1
Dim item As UltraListViewItem = selectedItems(i)
Dim listViewDrag As UltraListView = item.Control
If listViewDrag.Equals(listViewDrop) Then
Exit For
MsgBox(item.Key)
Next
dataObject = Nothing
Hi,
Your sample is raising an Exception inside the UltraGrid1_DragDrop event. It's not showing up all the time, though. Seems like something must be catching it. But if you turn on all exception in the IDE, you will see it. The problem is that you are trying to cast the sender into a ListView, but the sender is the control that triggered the event, so it's the grid, not the ListView.
I'm not sure why you are doing that, anyway, since your With block is never used. But anyway, if you change it to:
With CType(sender, UltraGrid) If e.Data.GetDataPresent(GetType(UltraListViewItem)) Then Dim draggedItem As UltraListViewItem = CType(e.Data.GetData(GetType(UltraListViewItem)), UltraListViewItem) MsgBox(draggedItem.Key) End If End With
Or delete the With block entirely, it's working fine.