Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
570
winListView drag an drop to winGrid not working
posted

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

WinListViewDragToWinGrid.zip
Parents
  • 469350
    Offline posted

    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.

Reply Children
No Data