Button click Move up/Move down in C# - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Button click Move up/Move down in C#

Last post 07-06-2009 11:49 AM by wiibur. 10 replies.
Page 1 of 1 (11 items)
Sort Posts: Previous Next
  • 06-30-2009 12:29 PM

    • wiibur
    • Not Ranked
    • Joined on 06-26-2009
    • Posts 9

    Button click Move up/Move down in C#

      Hi all. I am trying to do a basic button functionality thing where you are able to move nodes up or down, in a repeating section or table. Now I know there is some VBScript at http://blogs.msdn.com/infopath/archive/2005/02/23/378968.aspx. This should be simple to port over to C# (which I need to do) but there are some nuances I can't figure out. How do I select the current node with the C# version? In VBScript you can just set currentNode = eventObj.source, but in C# the argument variable e is of type XPathNavigator. Can someone please point me in the right direction. I have played around with all the functionality in an XPathNavigator object and cannot get it to return the current node in any way. I might be going about this completely wrong. 

     Thanks for the help. Below is my code.  

     

            public void CTRL27_11_Clicked(object sender, ClickedEventArgs e)
            {
                XmlNode currentNode, parentNode, prevNode;
                
                currentNode = /* what goes here? */
                parentNode = currentNode.ParentNode;
                prevNode = currentNode.PreviousSibling;

                if (prevNode != null)
                {
                    parentNode.RemoveChild(currentNode);
                    parentNode.InsertBefore(currentNode, prevNode);
                }
               
             
            }

            public void CTRL28_11_Clicked(object sender, ClickedEventArgs e)
            {
                XmlNode currentNode, parentNode, nextNode;

                currentNode = /* what goes here? */
                parentNode = currentNode.ParentNode;
                nextNode = currentNode.NextSibling;
               
                if (nextNode != null)
                {
                    parentNode.RemoveChild(nextNode);
                    parentNode.InsertBefore(nextNode, currentNode);
                }
               
            }

     

     I just don't see how you are able to move the nodes around in Clicked( ) in C#, when all you are passed is an XPathNavigator. All of the XPathNavigator methods are for moving itself to other nodes. What I want to do is actually move the nodes themselves.

     Thanks again.

     

  • 07-02-2009 07:53 AM In reply to

    • wiibur
    • Not Ranked
    • Joined on 06-26-2009
    • Posts 9

    Re: Button click Move up/Move down in C#

     This is a pretty simple problem right? Just how do you access a current node when all you are given to work with is an XPathNavigator?

  • 07-02-2009 04:56 PM In reply to

    Re: Button click Move up/Move down in C#

    Hi -- ClickedEventArgs e is one of the parameters for the clicked event. e.Source gets you the group that the button is in....this documentation from MSDN will give you some additional information.

    Hilary Stoupa

  • 07-06-2009 07:42 AM In reply to

    • wiibur
    • Not Ranked
    • Joined on 06-26-2009
    • Posts 9

    Re: Button click Move up/Move down in C#

    I have been through the documentation there. Is this problem even feasible, because I still cannot figure out how to access the node itself in order to move it to a different location.

     

    Thanks.

  • 07-06-2009 09:27 AM In reply to

    Re: Button click Move up/Move down in C#

     As Hilary already said, the current node can be accessed by e.Source.  Here's code for moving an element up within its section.  I'll let you figure out the down version:

              public void CTRL5_5_Clicked(object sender, ClickedEventArgs e)
            {          
                XPathNavigator currentNode = e.Source;

                XPathNavigator prevSibling = currentNode.SelectSingleNode("preceding-sibling::my:group2[1]", NamespaceManager);

                if (prevSibling != null)
                {
                    prevSibling.InsertBefore(currentNode);
                    // The line above creates a copy, so delete the original
                    currentNode.DeleteSelf();
                }
            }


    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 07-06-2009 09:34 AM In reply to

    • wiibur
    • Not Ranked
    • Joined on 06-26-2009
    • Posts 9

    Re: Button click Move up/Move down in C#

    But is this solution generic?

    It looks like you are selecting the previous node based on it's name? I don't have a set name for each node nor a set number of nodes. The nodes that I need to be able to move up/down are in a repeating section which the user adds however many nodes he needs.
  • 07-06-2009 11:10 AM In reply to

    • wiibur
    • Not Ranked
    • Joined on 06-26-2009
    • Posts 9

    Re: Button click Move up/Move down in C#

    Or is preceding-sibling actually some sort of keyword?
  • 07-06-2009 11:24 AM In reply to

    • wiibur
    • Not Ranked
    • Joined on 06-26-2009
    • Posts 9

    Re: Button click Move up/Move down in C#

  • 07-06-2009 11:27 AM In reply to

    Re: Button click Move up/Move down in C#

     The my:group2 part is not generic, but in almost all cases, there is only one repeating node in a given repeating section.  Is that not the case in your form?

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 07-06-2009 11:30 AM In reply to

    • wiibur
    • Not Ranked
    • Joined on 06-26-2009
    • Posts 9

    Re: Button click Move up/Move down in C#

     Yea that's the case, just wasn't familiar with the previous-sibling subpath, or XPaths in general. Do you have to use the whole XPath location of the node with preceding-sibling? Or just its immediate group?

  • 07-06-2009 11:49 AM In reply to

    • wiibur
    • Not Ranked
    • Joined on 06-26-2009
    • Posts 9

    Re: Button click Move up/Move down in C#

     I got it working. Thanks for your help.

Page 1 of 1 (11 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.