473,545 Members | 2,049 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with dragging from listview to treeview

I am trying to adapt some code that I have where I drag and drop from two
treeview controls. Now I want to drag and drop from a listview to a treeview.
Whatever I do does not work and I cannot find any good articals on the net on
how to do so. I have attached my original code for the two treeview
controls. Can anybody point out where I need to make changes?
Dim NewNode As Windows.Forms.T reeNode
Dim imgIndex As Windows.Forms.T reeNode
If e.Data.GetDataP resent("System. Windows.Forms.T reeNode", False) Then
Dim pt As Drawing.Point
Dim destinationNode As Windows.Forms.T reeNode
pt = CType(sender, Windows.Forms.T reeView).PointT oClient(New
Drawing.Point(e .X, e.Y))
destinationNode = CType(sender,
Windows.Forms.T reeView).GetNod eAt(pt)
NewNode = CType(e.Data.Ge tData("System.W indows.Forms.Tr eeNode"),
Windows.Forms.T reeNode)
If Not destinationNode .Equals(NewNode ) Then

'now adding to the shs tree view
destinationNode .Nodes.Add(CTyp e(NewNode.Clone ,
Windows.Forms.T reeNode))
imgIndex = destinationNode
imgIndex.ImageI ndex = 2
imgIndex.Select edImageIndex = 2
'imgIndex.Tag = "U" & strStatus
destinationNode .Expand()

End If
End If
Nov 11 '08 #1
1 1937
Andrew wrote:
I am trying to adapt some code that I have where I drag and drop from two
treeview controls. Now I want to drag and drop from a listview to a treeview.
Can anybody point out where I need to make changes?

Imports System.Windows. Forms

Private Sub X_Drag*( ... ) Handles X.Drag*

Dim tv as TreeView = DirectCast( sender, TreeView )

' For a ListViewItem, you need to look for a /different/ Type
' (S.W.F.ListView Item) here

If e.Data.GetDataP resent("System. Windows.Forms.T reeNode", False) Then

' Isn't it annoying there's no e.Location?
Dim pt As Drawing.Point _
= tv.PointToClien t(New Drawing.Point(e .X, e.Y))

Dim destinationNode As TreeNode _
= tv.GetNodeAt( pt )

' You can't cast a ListViewItem into a TreeNode.
' You'll have to create a /new/ TreeNode and set it up
' based on the given ListViewItem (or TreeNode, if you
' want to support Drag-and-Drop within the Tree as well!
Dim NewNode As TreeNode _
= CType(e.Data.Ge tData("System.W indows.Forms.Tr eeNode") _
, TreeNode)

' Everything else should work as given ...

If Not destinationNode .Equals( NewNode ) Then

' If you're creating a new Node from a ListViewItem,
' the above will never be True, but anyway ...

Dim newIndex as Integer _
= destinationNode s.Nodes.Add( NewNode.Clone() )
NewNode = destinationNode .Nodes( newIndex )

With NewNode
.ImageIndex = 2
.SelectedImageI ndex = 2
End With

destinationNode .Expand()

End If
End If
End Sub

HTH,
Phill W.
Nov 17 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
1877
by: fgh | last post by:
Hello, two questions please: 1) In a treeview, I want to display folders like it is done in Windows Explorer. Do I have to do this manually or can I set something up in VS.NET 2003? 2) Most importantly, in Windows Explorer, you can drag the treeview's right edge to resize it to your will. How can I do this with my treeview (at runtime...
1
2415
by: (Pete Cresswell) | last post by:
TabControl on the right side of a form with two tabs: Tab #1 contains two subforms that show some dynamic query results. Tab #2 contains a ListView that gets dynamically populated as the user navigates a TreeView on the left side of the form. The first time I load the ListView, if the tab containing it is not selected (i.e. the ListView...
1
3440
by: newbie | last post by:
Hello, I maybe asking too much in a single posting, but here it goes: I building a windows form that mimic's the Outlook XP GUI. Its a three pane form that will allow a user to view and edit records in a database. A Treeview in the left pane, a Listview in the TopRight Pane, and a PropertyGrid in the BottomRight; The Treeview will allow...
2
15231
by: Adam Klobukowski | last post by:
Hello i need to find out the last fully visible item of a Llistview. If it would be a treeview then it would be easy, I'm even thinkin of faking my treeview as listview, but maybe there is some easy way I don't see? -- Semper Fidelis Adam Klobukowski atari@gabo.pl
3
1498
by: Anil | last post by:
I want to invoke LabelEdit event of TreeView/ListView(property set to true) from another event what should I do? The scenario is like windows explorer. If u click F2, selected node or item will be editable. How to map that LabelEdit event with MenuClick event. Please help me out.
0
1858
by: Danny Tuppeny | last post by:
Hi all, I have a need to display a message list in the same way as Outlook Express/Thunderbird displays new posts (and probably most other newsreaders, like the one you're using now!). I know there are commercial options but a) I don't want to pay and b) they're all massively bloated. I want exactly a TreeList + ListView, and I want it to...
0
1850
by: alcurb | last post by:
I have a ListView control populated with 30 items. ListView height only allows you to see 20 rows at a time. I want to drag an item to the bottom of the list (to the last row), but ListView control doesn't automatically scroll as my mouse leaves the bottom edge of the control. Also if I'm dragging an item from the last row to the top row,...
1
2351
by: =?iso-8859-1?B?S2VyZW0gR/xtcvxrY/w=?= | last post by:
Hi, i am looking for a way to clear and fill a listview and right after a treeview nearly flicker and delay free. The TreeView and Listview contain Images and about 1000 Items. What can someone recommend me how i can do this, with as less delay and flicker as possible,... What are the right steps and methdods for this. What to do before...
0
2809
by: =?Utf-8?B?QW5kcmV3?= | last post by:
I have some code that I use to drag and drop from treeview to treeview, now I want to adapt the code to drag and drop from listview to treeview. I am having problems adapting the code nor can I find a good article on the web on how to do this. I have attached below my source code that I have not touched. Can anybody point out where I would...
0
7468
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7401
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7423
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7757
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5972
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3450
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3443
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1884
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1014
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.