My first time using TreeViews. I have TreeView1 set up to display my
directory structure just like Windows Explorer. I can drag & drop files and
folders over to TreeView2. I can re-arrange the structure in TreeView2
(putting files in different folders and such...like you do when you create a
structure for burning a CD).
I have two questions.
1. How can I remember the full path from TreeView1 (when it comes time to
actually do something with the arrangement in TreeView2)?
2. I have not been able to figure out how to get the DragOver part to work
correctly. In the code below, when I drag over a file node, it's supposed
to display the "not here" cursor. When I drag over a directory node (or the
root), it's supposed to display the "drop" cursor. It does fine except when
I drag over a file node and then drag off the file node. When I drag over
the file node, the cursor changes to "not here". When I drag off the file
node, I get an exception "object reference not set to an instance, try using
the NEW keyword". Looking for help to correct this.
Thanks.
Public Sub TreeViewISO_Dra gOver(ByVal sender As System.Object, ByVal e As
DragEventArgs) Handles TreeViewISO.Dra gOver
'Check that there is a TreeNode being dragged
If e.Data.GetDataP resent("System. Windows.Forms.T reeNode", True) = False Then
Exit Sub
'Get the TreeView raising the event (incase multiple on form)
Dim selectedTreevie w As TreeView = CType(sender, TreeView)
'As the mouse moves over nodes, provide feedback to
'the user by highlighting the node that is the
'current drop target
Dim pt As Point = CType(sender, TreeView).Point ToClient(New Point(e.X, e.Y))
Dim targetNode As TreeNode = selectedTreevie w.GetNodeAt(pt)
'See if the targetNode is currently selected,
'if so no need to validate again
If Not (selectedTreevi ew.SelectedNode Is targetNode) Then
'Select the node currently under the cursor
selectedTreevie w.SelectedNode = targetNode
'Check that the selected node is not the dropNode and
'also that it is not a child of the dropNode and
'therefore an invalid target
Dim dropNode As TreeNode =
CType(e.Data.Ge tData("System.W indows.Forms.Tr eeNode"), TreeNode)
If targetNode.Imag eIndex = 2 Then <== Exception thrown here...
e.Effect = DragDropEffects .None
Else
'Currently selected node is a suitable target
e.Effect = DragDropEffects .Move
End If
End If
End Sub 1 2303
1. Im not sure what your asking here. If you just want a path then why cant
you store it in a string? If you want the tree list structure then just
clone the node thats interests you (or its root) and store a reference to
this node in a variable.
2. If Not (selectedTreevi ew.SelectedNode Is targetNode)
If target node is Nothing then the code in the conditional still executes.
You then try to access a property of Nothing which is why the excepion gets
thrown.
targetNode.Imag eIndex
I would chnage the conditional too
If Not targetNot Is Nothing AndAlso (selectedTreevi ew.SelectedNode Is
targetNode) then
RR
"Terry Olsen" <to******@hotma il.com> wrote in message
news:OY******** ******@TK2MSFTN GP14.phx.gbl... My first time using TreeViews. I have TreeView1 set up to display my directory structure just like Windows Explorer. I can drag & drop files
and folders over to TreeView2. I can re-arrange the structure in TreeView2 (putting files in different folders and such...like you do when you create
a structure for burning a CD).
I have two questions.
1. How can I remember the full path from TreeView1 (when it comes time to actually do something with the arrangement in TreeView2)? 2. I have not been able to figure out how to get the DragOver part to work correctly. In the code below, when I drag over a file node, it's supposed to display the "not here" cursor. When I drag over a directory node (or
the root), it's supposed to display the "drop" cursor. It does fine except
when I drag over a file node and then drag off the file node. When I drag over the file node, the cursor changes to "not here". When I drag off the file node, I get an exception "object reference not set to an instance, try
using the NEW keyword". Looking for help to correct this.
Thanks. Public Sub TreeViewISO_Dra gOver(ByVal sender As System.Object, ByVal e As DragEventArgs) Handles TreeViewISO.Dra gOver 'Check that there is a TreeNode being dragged If e.Data.GetDataP resent("System. Windows.Forms.T reeNode", True) = False
Then Exit Sub 'Get the TreeView raising the event (incase multiple on form) Dim selectedTreevie w As TreeView = CType(sender, TreeView) 'As the mouse moves over nodes, provide feedback to 'the user by highlighting the node that is the 'current drop target Dim pt As Point = CType(sender, TreeView).Point ToClient(New Point(e.X,
e.Y)) Dim targetNode As TreeNode = selectedTreevie w.GetNodeAt(pt) 'See if the targetNode is currently selected, 'if so no need to validate again If Not (selectedTreevi ew.SelectedNode Is targetNode) Then 'Select the node currently under the cursor selectedTreevie w.SelectedNode = targetNode 'Check that the selected node is not the dropNode and 'also that it is not a child of the dropNode and 'therefore an invalid target Dim dropNode As TreeNode = CType(e.Data.Ge tData("System.W indows.Forms.Tr eeNode"), TreeNode) If targetNode.Imag eIndex = 2 Then <== Exception thrown here... e.Effect = DragDropEffects .None Else 'Currently selected node is a suitable target e.Effect = DragDropEffects .Move End If End If End Sub
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Karsten Schramm |
last post by:
Hi,
if I drag an Outlook.MailItem to a Windows-Explorer window a
<subject>.msg file will be created.
Now I try to drag & drop a mail item to my own WinForm app.
Unfortunately it doesn't work. In the "drop event" are eight
DataFormats (e.Data.GetFormats()) but the important one (imho)
"FileContents" is "Nothing"/"null".
|
by: Plumer |
last post by:
Hello everyone,
Yesterday I posted a message about implementing drag & drop in a TreeView
control.
I'm having real difficulty getting this to work -- the process seems to be
incredibly delicately balanced and finding my way through it has descended
into one of those awful situations which I refer to as guess & test.
From the point at which DoDragDrop() function is called until some later
|
by: Grey |
last post by:
I need to design a workflow application with C#. I want to design an UI with
some workflow components which they can be drag & drop anywhere in order to
design the workflow for the application users. Moreover, when the user
double click on the component, they can define some routing rules for the
process. Is it possible to have such fancy UI in C#?? Any reference sites or
tutorial??
Million Thanks.
|
by: Ivo Tcholakov |
last post by:
Is it possible to drag and drop controls in an aspx page at runtime ?
Meaning i have developed a ASP.NET web form, the web form is now downloaded
in IE - now can i have this form to detect mouse events, and provide drag
and drop functionality of the controls ?
Thank You
Ivo Tcholakov
|
by: jojobar |
last post by:
Hello,
I look at the asp.net 2.0 web parts tutorial on the asp.net web site. I
tried to run it under firefox browser but it did not run.
If I want to use this feature in a commercial product where the user can run
on firefox/mozilla, what would be a good approach.
1. Should I overwrite the javascript code drag-and-drop to make it more
browser independent. If I want to go this route, can anybody provide me a
| |
by: Goldwind |
last post by:
Hi,
I"m trying to use drag & drop of text from one text box to
another but without suceess.
Microsoft presented an example in "101 code samples" BUT
in this example the code select and drag all the text in
the TextBox, wether the user wants or not.
I need to drag only the selected text (changing the
example causes it not to work).
|
by: VB Programmer |
last post by:
In VB.NET 2005 (winform) any sample code to drag & drop items between 2
listboxes? Thanks!
|
by: sesar |
last post by:
How can I impement drag&drop for simple 'dialog base' application... I
want to drag&drop txt file and load the text to variable
|
by: Romulo NF |
last post by:
Greetings,
I´m back here to show the new version of the drag & drop table columns (original script ). I´ve found some issues with the old script, specially when trying to use 2 tables with drag&drop on the same page (which was not possible). Now i´ve a new concept of the script, more object oriented.
I´ve also commented the whole code so you guys can easier understand it engine.
What exactly we need when trying to make a column drag &...
|
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 usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |