drag drop from Listview to Treeview...

C

Co

Hi All,

I use following code to drag drop an item from a Listview onto a
Treeview but the code doesn't recognize the ListviewItem:

Public Sub TreeView_DragDrop( _
ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.DragEventArgs) _
Handles TreeView.DragDrop

If e.Data.GetDataPresent("System.Windows.Forms.ListViewItem",
False) Then
Dim pt As Point

Dim DestinationNode
pt = TreeView.PointToClient(New Point(e.X, e.Y))

DestinationNode = TreeView.GetNodeAt(pt)
MsgBox(DestinationNode.row("ID"))
End If

End Sub

The Listview displays files in every node in the Treeview.
When I want to drag a file from one node to another I just drag it
onto the new node and let go.
My DragDrop code however doesn't recognizes it as a ListviewItem:
If e.Data.GetDataPresent("System.Windows.Forms.ListViewItem",
False) Then

What am I doing wrong?

Regards
Marco
The Netherlands
 
A

Armin Zingler

Co said:
Hi All,

I use following code to drag drop an item from a Listview onto a
Treeview but the code doesn't recognize the ListviewItem:

Public Sub TreeView_DragDrop( _
ByVal sender As System.Object, _
ByVal e As System.Windows.Forms.DragEventArgs) _
Handles TreeView.DragDrop

If e.Data.GetDataPresent("System.Windows.Forms.ListViewItem",
False) Then
Dim pt As Point

Dim DestinationNode
pt = TreeView.PointToClient(New Point(e.X, e.Y))

DestinationNode = TreeView.GetNodeAt(pt)
MsgBox(DestinationNode.row("ID"))
End If

End Sub

The Listview displays files in every node in the Treeview.
When I want to drag a file from one node to another I just drag it
onto the new node and let go.
My DragDrop code however doesn't recognizes it as a ListviewItem:
If e.Data.GetDataPresent("System.Windows.Forms.ListViewItem",
False) Then

What am I doing wrong?

Do yourself a favor and switch Option Strict On.

I've tried it and it works. How does your DoDragDrop call look like?

You can use e.Data.GetFormats to find out which formats are available, for
example:

Debug.WriteLine(String.Join(vbCrLf, e.Data.GetFormats()))

In addition,

If e.Data.GetDataPresent(GetType(ListViewItem)) Then

is safer because this type name is checked by the compiler, not at runtime.


Armin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top