473,847 Members | 1,877 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Moving Nodes

Sl1ver
196 New Member
I've got a problem, i got the nodes to move but
1. they copy nodes(if you drag it to 3 different places it will actually have 3 of the same nodes)
2. i want to make the nodes, if moved update the new nodes locations

This is my coding
Expand|Select|Wrap|Line Numbers
  1.  private void tvDescriptions_MouseDown(object sender, MouseEventArgs e)
  2.         {
  3.             TreeView tree = (TreeView)sender;
  4.  
  5.             // Get the node underneath the mouse.
  6.             TreeNode node = tree.GetNodeAt(e.X, e.Y);
  7.  
  8.             // Start the drag-and-drop operation with a cloned copy of the node.
  9.             if (node != null)
  10.             {
  11.                 tree.DoDragDrop(node.Clone(), DragDropEffects.Copy);
  12.             }
  13.         }
  14.  
  15.         private void tvDescriptions_DragOver(object sender, DragEventArgs e)
  16.         {
  17.             // Get the tree.
  18.             TreeView tree = (TreeView)sender;
  19.  
  20.             // Drag and drop denied by default.
  21.             e.Effect = DragDropEffects.None;
  22.  
  23.             // Is it a valid format?
  24.             if (e.Data.GetData(typeof(TreeNode)) != null)
  25.             {
  26.                 // Get the screen point.
  27.                 Point pt = new Point(e.X, e.Y);
  28.  
  29.                 // Convert to a point in the TreeView's coordinate system.
  30.                 pt = tree.PointToClient(pt);
  31.  
  32.                 // Is the mouse over a valid node?
  33.                 TreeNode node = tree.GetNodeAt(pt);
  34.                 if (node != null)
  35.                 {
  36.                     e.Effect = DragDropEffects.Copy;
  37.                     tree.SelectedNode = node;
  38.                 }
  39.             }
  40.         }
  41.  
  42.         private void tvDescriptions_DragDrop(object sender, DragEventArgs e)
  43.         {
  44.             // Get the tree.
  45.             TreeView tree = (TreeView)sender;
  46.  
  47.             // Get the screen point.
  48.             Point pt = new Point(e.X, e.Y);
  49.  
  50.             // Convert to a point in the TreeView's coordinate system.
  51.             pt = tree.PointToClient(pt);
  52.  
  53.             // Get the node underneath the mouse.
  54.             TreeNode node = tree.GetNodeAt(pt);
  55.  
  56.             // Add a child node.
  57.             node.Nodes.Add((TreeNode)e.Data.GetData(typeof(TreeNode)));
  58.  
  59.             // Show the newly added node if it is not already visible.
  60.             node.Expand();
  61.         }
  62.  
  63.         private void tvDescriptions_ItemDrag(object sender, ItemDragEventArgs e)
  64.         {
  65.  
  66.         }
  67.  
Apr 9 '09 #1
6 4067
tlhintoq
3,525 Recognized Expert Specialist
So you want a 'move' not a copy? Am I reading that right?
Do the copy, then at the node where you moved it from perform a .Remove

At line 6 you learn which node is being copied (naming it 'node')
between lines 11 and 12 add... tree.Nodes.Remo ve(node);
Apr 11 '09 #2
Sl1ver
196 New Member
Thanx, you really know your stuff. How or where will i post a event to update the database with the new information?
Apr 14 '09 #3
tlhintoq
3,525 Recognized Expert Specialist
where will i post a event to update the database with the new information?
I don't know your program as well as you do, so I can only give you a generic answer... I would raise and event to perform an update after I'm done with all my changes. Where that fits into what you've engineered, only you know. This treeview could be on its own user control, or it could be on a floating pallet or it could be in the middle of your one and only form. I can't say. But that's the beauty of events... As long as you have another class 'listening' (subscribed) to the event it will still work.
Apr 14 '09 #4
Sl1ver
196 New Member
Hi,

this is my coding. I get a error that states "Must use a updatable query" and if you double click on the nodes the whole program freezes. any help?

Expand|Select|Wrap|Line Numbers
  1.  private void tvLocations_MouseDown(object sender, MouseEventArgs e)
  2.         {
  3.             TreeView tree = (TreeView)sender;
  4.  
  5.             // Get the node underneath the mouse.
  6.             TreeNode node = tree.GetNodeAt(e.X, e.Y);
  7.  
  8.             // Start the drag-and-drop operation with a cloned copy of the node.
  9.             if (node != null)
  10.             {
  11.                 tree.DoDragDrop(node, DragDropEffects.Copy);
  12.                 //node.Remove();
  13.  
  14.             }
  15.         }
  16.  
  17.         private void tvLocations_DragOver(object sender, DragEventArgs e)
  18.         {
  19.             // Get the tree.
  20.             TreeView tree = (TreeView)sender;
  21.  
  22.  
  23.             // Drag and drop denied by default.
  24.             e.Effect = DragDropEffects.None;
  25.  
  26.             // Is it a valid format?
  27.             if (e.Data.GetData(typeof(TreeNode)) != null)
  28.             {
  29.                 // Get the screen point.
  30.                 Point pt = new Point(e.X, e.Y);
  31.  
  32.                 // Convert to a point in the TreeView's coordinate system.
  33.                 pt = tree.PointToClient(pt);
  34.  
  35.                 // Is the mouse over a valid node?
  36.                 TreeNode node = tree.GetNodeAt(pt);
  37.                 if (node != null)
  38.                 {
  39.                     e.Effect = DragDropEffects.Copy;
  40.                     tree.SelectedNode = node;
  41.  
  42.                 }
  43.             }
  44.         }
  45.  
  46.         private void tvLocations_DragDrop(object sender, DragEventArgs e)
  47.         {
  48.             try
  49.             {
  50.                 // Get the tree.
  51.                 TreeView tree = (TreeView)sender;
  52.  
  53.                 tree.BeginUpdate();
  54.  
  55.                 // Get the screen point.
  56.                 Point pt = new Point(e.X, e.Y);
  57.  
  58.                 // Convert to a point in the TreeView's coordinate system.
  59.                 pt = tree.PointToClient(pt);
  60.  
  61.                 // Get the node underneath the mouse.
  62.                 TreeNode node = tree.GetNodeAt(pt);
  63.  
  64.                 TreeNode childNode = (TreeNode)e.Data.GetData(typeof(TreeNode));
  65.  
  66.                 // Remoce this node
  67.                 tree.Nodes.Remove(childNode);
  68.  
  69.                 // Add the node to the new parent
  70.                 node.Nodes.Add(childNode);
  71.  
  72.                 // Show the newly added node if it is not already visible.
  73.                 node.Expand();
  74.  
  75.                 tree.EndUpdate();
  76.  
  77.                 UpdateDBStructure(childNode.Tag, node.Tag);
  78.             }
  79.             catch (Exception ex)
  80.             {
  81.                 MessageBox.Show("Error: " + ex.Message);
  82.             }
  83.         }
  84.  
  85.         private void tvLocations_ItemDrag(object sender, ItemDragEventArgs e)
  86.         {
  87.  
  88.         }
  89.  
  90.         private void UpdateDBStructure(object Id, object parentId)
  91.         {                        
  92.             OleDbConnection mConn = new OleDbConnection(strCon);
  93.  
  94.             mConn.Open();            
  95.  
  96.             string UpdateStr = @"UPDATE qx_AssetLocation SET 
  97.                                  alc__acl_id = " + parentId + 
  98.                                " where alc__ID = " + Id;
  99.  
  100.             OleDbCommand myCmd = mConn.CreateCommand();
  101.             myCmd.CommandText = UpdateStr;
  102.             try
  103.             {
  104.                 myCmd.ExecuteNonQuery();
  105.                 //MessageBox.Show("Data added to database");
  106.  
  107.             }
  108.             catch (Exception ed)
  109.             {
  110.                 MessageBox.Show("Error: " + ed.Message, "Error");
  111.             }
  112.             finally
  113.             {
  114.                 myCmd.Dispose();
  115.                 mConn.Close();
  116.                 mConn.Dispose();
  117.                 tvLocations.Nodes.Clear();
  118.                 //PopulateTree();
  119.             }
  120.  
  121.  
  122.         }
Apr 15 '09 #5
tlhintoq
3,525 Recognized Expert Specialist
Put a breakpoint in your UpdateDbStructu re (line 92 or so) and walk through it one step at a time with F-10. See if that helps you find the exact location and nature of the issue.
Apr 15 '09 #6
Sl1ver
196 New Member
thanx man for the help, things are working
Apr 16 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
1285
by: alanrn | last post by:
I am using a TreeView to display the hierarchy of a strongly-typed collection (inherited from CollectionBase). The order of the nodes in the TreeView is strictly tied to the order in which they appear in the underlying collection. However, the user must be able to reorder certain items in the collection--and, hence, the TreeView. I have created a context-sensitive menu that allows the user to move an item in the collection either up or...
4
1535
by: ewosch | last post by:
Hi, is there a possibility to move a node from one child position to another ? thanks Wolfgang
0
877
by: Victor | last post by:
I need to move a node to different position at the same level. Internet explorer does very intiutive using a line where the node should be inserted: -How a line may be presented between nodes indicating the position to insert? -How to get the nodes (node up and down the cursor position)? Thanks Victor
1
1381
by: Victor | last post by:
I need to move a node to different position but at the same level. Internet explorer does very intiutive presenting a line where the node should be inserted (when you want insert between two nodes no under a node). Have you got an example. Thanks Victor
1
1302
by: db2udbgirl | last post by:
When I installed DB2 UDB 8.2 on AIX 5.3 it got installed in /home/db2inst1 (and I didn't care about it much then but now I would like to move the same instance of DB2 to a dedicated filesystem. May I know the steps involved in doing this migration activity. Thanks, db2udbgirl
4
1829
by: hari60133 | last post by:
In single/double linked list having 10 nodes due to some memory problems the 4th next node is pointing to 3rd node not to a 5 th node, how to findout the 5th node? please explain concept and send code .
2
1242
by: Bart Steur | last post by:
Hi, I would like to know what is the best way to move a node within a tree/treenodecollection (not using Drag/Drop). It can't be done by changing the index. Found some examples with remove/insert, but is that the only way? Thanks, Bart
0
1450
by: Malcolm Dew-Jones | last post by:
I have a test= that works but I would like to figure out how to move it into a match=. (Ok, that's unclear but pls keep reading.) Part of my XSLT file looks like this. <xsl:template match="@*|node()"> <xsl:choose> <xsl:when test=" count(.//w:fldSimple/@w:instr)=1 and
1
2063
by: barantamer | last post by:
hello, i am actually a php developer and i am new to java i think i have a pretty easy question. How can i do this exactly in java ? foreach ($rootnode->children() as $child) { //some code here }
0
9886
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9730
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10983
Oralloy
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...
0
10647
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10338
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7882
isladogs
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...
0
5719
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...
1
4527
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
2
4119
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.