473,405 Members | 2,349 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Moving Nodes

Sl1ver
196 100+
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 4039
tlhintoq
3,525 Expert 2GB
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.Remove(node);
Apr 11 '09 #2
Sl1ver
196 100+
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 Expert 2GB
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 100+
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 Expert 2GB
Put a breakpoint in your UpdateDbStructure (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 100+
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
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...
4
by: ewosch | last post by:
Hi, is there a possibility to move a node from one child position to another ? thanks Wolfgang
0
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...
1
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...
1
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...
4
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...
2
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...
0
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...
1
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) { ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...
0
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...

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.