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

Home Posts Topics Members FAQ

Nudge TreeNode Sibling Order Up or Down

10 New Member
I found this article on how to nudge the treenode items up or down in the order of a treeview control. The problem is it's in C# and I know nothing about C#. In fact, C# scares me (I think it's the pound sign, idk...or maybe it's the letter C) I've included the code here. Could someone do me the huge favor of converting it to VB.Net?

Expand|Select|Wrap|Line Numbers
  1. public bool NudgeDown(TreeNode node)
  2.      {
  3.  
  4.        int newIndex = 0;
  5.        TreeNode nodeClone = null;
  6.  
  7.  
  8.        try
  9.        {
  10.  
  11.          if (node == null) { return false; }
  12.  
  13.          newIndex = node.Index + 2;
  14.  
  15.          if (newIndex > node.Parent.Nodes.Count) { return false; }
  16.  
  17.  
  18.          nodeClone = (TreeNode)node.Clone();
  19.  
  20.          node.Parent.Nodes.Insert(newIndex, nodeClone);
  21.  
  22.          node.Parent.Nodes.Remove(node);
  23.  
  24.          nodeClone.TreeView.SelectedNode = nodeClone; 
  25.  
  26.         }
  27.         catch (Exception) { throw; }
  28.         return true;
  29.      }
  30.  
  31.  
  32.      public bool NudgeUp(TreeNode node)
  33.      {
  34.        int newIndex = 0;
  35.        TreeNode nodeClone = null;
  36.  
  37.        try
  38.        {
  39.  
  40.          if (node == null) { return false; }
  41.  
  42.          if (node.Index == 0) { return false; }
  43.  
  44.          newIndex = node.Index - 1;
  45.  
  46.          nodeClone = (TreeNode)node.Clone();
  47.  
  48.          node.Parent.Nodes.Insert(newIndex, nodeClone);
  49.  
  50.          node.Parent.Nodes.Remove(node);
  51.  
  52.          nodeClone.TreeView.SelectedNode = nodeClone; 
  53.        }
  54.        catch (Exception) { throw; }
  55.        return true;
  56.     }
Oct 28 '08 #1
2 1405
Curtis Rutland
3,256 Recognized Expert Specialist
Well, we can't do your work for you, but we can help you make it easier.

Try it yourself, and we can help you when you get stuck. Trust me, it's worth the effort. Since the languages work on the same Framework, and they aren't that ridiculously different, it makes sense to understand the basics of the one you aren't going to use. That way, you will be able to understand examples, and won't need someone to translate everything for you.

Here's a great resource to get you started:
http://www.harding.edu/fmccown/vbnet...omparison.html
Its a conversion chart. It lists the way VB.NET does things, and the way C# does things.

And I promise, when you are done, you'll be less scared of C#.
Oct 28 '08 #2
dutsnekcirf
10 New Member
I actually figured it out on my own, but I will use that link from now on. And you're right, I'm not nearly as afraid of C# as I was before.

Here's the code:

Expand|Select|Wrap|Line Numbers
  1. Private Sub NudgeUpButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NudgeUpButton.Click
  2.  
  3.         Dim NodeClone As TreeNode = Nothing
  4.         Dim node As TreeNode = PredatorTreeview.SelectedNode
  5.         Dim NewIndex = 0
  6.  
  7.         Try
  8.  
  9.             If node Is Nothing Then
  10.  
  11.                 MsgBox("Please select a node to nudge.")
  12.                 Exit Sub
  13.  
  14.             Else
  15.  
  16.                 NewIndex = node.Index - 1
  17.  
  18.                 If NewIndex > node.Parent.Nodes.Count Then Exit Sub
  19.  
  20.                 NodeClone = node.Clone
  21.  
  22.                 node.Parent.Nodes.Insert(NewIndex, NodeClone)
  23.  
  24.                 node.Parent.Nodes.Remove(node)
  25.  
  26.                 PredatorTreeview.SelectedNode = NodeClone
  27.  
  28.                 End If
  29.  
  30.         Catch ex As Exception
  31.  
  32.             MsgBox(ex.Message)
  33.  
  34.         End Try
  35.  
  36.     End Sub
  37.  
  38.     Private Sub NudgeDownButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NudgeDownButton.Click
  39.  
  40.         Dim NodeClone As TreeNode = Nothing
  41.         Dim node As TreeNode = PredatorTreeview.SelectedNode
  42.         Dim NewIndex = 0
  43.  
  44.         Try
  45.  
  46.             If node Is Nothing Then
  47.  
  48.                 MsgBox("Please select a node to nudge.")
  49.                 Exit Sub
  50.  
  51.             Else
  52.  
  53.                 NewIndex = node.Index + 2
  54.  
  55.                 If NewIndex > node.Parent.Nodes.Count Then Exit Sub
  56.  
  57.                 NodeClone = node.Clone
  58.  
  59.                 node.Parent.Nodes.Insert(NewIndex, NodeClone)
  60.  
  61.                 node.Parent.Nodes.Remove(node)
  62.  
  63.                 PredatorTreeview.SelectedNode = NodeClone
  64.  
  65.                 End If
  66.  
  67.         Catch ex As Exception
  68.  
  69.             MsgBox(ex.Message)
  70.  
  71.         End Try
  72.  
  73.     End Sub
Oct 28 '08 #3

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

Similar topics

3
11292
by: Peter Rohleder | last post by:
Hi, I'm using a style-sheet where I make use of the XPATH-"following-sibling"-expression. The part which makes problems looks similar to the following code: --------------------------- <xsl:for-each select="headdata/extension/person">
2
5876
by: Michael K?nig | last post by:
Hello, I've an XML-file structured like this <table> <tr> <td>Nombre:</td> <td>Joseph</td> <td>Apellido:</td> <td>Ratzinger</td>
5
10221
by: nevin | last post by:
Hi, If I have a TreeView with loads of Nodes and they all have children etc, how do I find the index of a given node when I only know the Text value? If I use TreeView.Nodes.IndexOf(new TreeNode(textvalueofname)) it always returns -1 and a TreeView.Nodes.Contains(etc.. always is false. I expect that it is only looking in the local Nodes...
8
5427
by: kurotsuke | last post by:
Hi, I need to clone a class (called NodeAbstract) that I derived from TreeNode. I need to clone it to support drag and drop on the treeview. I tried to use the MemberWiseClone (in my own Clone() method) method but with no success. The cloned object seems to be correctly created but I cannot add it to the treeview (I get no error message...
0
1226
by: Kathy Burke | last post by:
I'm providing the following syntax in hopes someone could tell me why I get an object reference error on the second one. The first one works, using an xmlDocument, the second one immediately follows and uses the same xmlDocument. It works if the result is not Nothing. I've used similar xpath expressions (but never with the following-sibling...
3
1823
by: markaelkins | last post by:
Hi. I am trying to enter a variable in the treenodesrc of a treenode. I am basically trying to send an ID variable into sql to return different records. I've searched everywhere and cannot find the answer. I'd appreciate and help. Thanks. What I'm doing is creating a treeview with the structure as follows (this is the expanded view): -...
3
4021
by: tanya foster | last post by:
Hello, I am re-writing a visual basic .net application(visual studio 2003) in an asp.net application(visual studio 2005). The vb.net application relied on a treeview and hence, treenodes. The treeview and treenode class in asp.net is limited compared to vb.net's. In vb.net, the treenode had a nextnode property which was equivalent to...
3
2248
by: moni | last post by:
Hi, I wanted to know if there was any way by which I could make a treenode control an item on my listview control. I have tried doing that..but the listview control does not allow me to add a treenode to it. This is allowed: item1 = new ListViewItem(p1.DisplayName);
12
3649
by: apicard | last post by:
I have a simple document like this: <Accept> <XXXX/> <Token image="From"/> <Date value="2007-01-01"/> <Token image="To"/> <Date value="2007-01-01"/> </Accept>
0
7475
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
7409
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...
0
7664
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. ...
0
7918
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...
1
7436
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
7766
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
4958
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1022
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
715
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.