none
trying to implement a "reset" button RRS feed

  • Question

  • I am trying to have a button that when pressed it resets all of the form's objects to their default form.  The problem is with the repeating table that I have: a few set rows have their own values and I cant figure out how to change those fields back to their default values.
    Any suggestions for the simplest way to do this?  thanks 

    Wednesday, May 27, 2009 10:13 PM

Answers

  • You can write code to reset form data to default on MyRessetButton_Clicked event

     public void MyRessetButton_Clicked(object sender, ClickedEventArgs e)
            {
                XPathNavigator elemStoreNumber = this.MainDataSource.CreateNavigator()
                        .SelectSingleNode("//my:StoreNumber", this.NamespaceManager);

                elemStoreNumber.SetValue(string.Empty);


               //  Write code to reset value for rest of the form fields


            }


    I am not sure if this the best solution though



    Regards
    Ashraf ul Islam
    Sharepoint Consultant

    Thursday, May 28, 2009 12:37 PM
  • Actually this is not as simple at it looks, the solutions depends on your datasource, an example could be

    mydata
    mydataset
    repeatingfolder
    datax
    datay

    if that is similar to your data you have to attach code to your form, 
    1.- add a button to your form and in properties select add custom code..
    2.- in VS do a selectsinglenode(mydata/mydataset/repeatingfolder , this.namespacemanager).xml 
    3.- put a break operation and debug the form so you can view the content of the node in xml in a quick view
    4.-copy the xml structure
    5.-exit the debug operation
    6.- put the xml  into a string variable in the form
    7.- modify the selectsinglenode(xpath, namespacemanager) to get the parent node
    8.- in the parent node set the inner xml used in 6.

    Example :

                    XPathNavigator root = MainDataSource.CreateNavigator();
                  
    
                    string xmlObjetivoTactico = @"
    	<my:URL xmlns:my='http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-09-26T18:40:28'>
    		<my:url>http://hildemoss/MyPictures/logosantander.jpg</my:url>
    		<my:url2>http://hildemoss/MyPictures/SantanderRed.jpg</my:url2>
    	</my:URL>
    	<my:debug xmlns:my='http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-09-26T18:40:28'></my:debug>
    ";
                 
                    
                    if (root.SelectSingleNode("/my:myFields", this.NamespaceManager) != null)
                    {
                        root.SelectSingleNode("/my:myFields", this.NamespaceManager).InnerXml = xmlObjetivoTactico;
                    }
                }
                catch (System.Exception ex)
                {
                    XPathNavigator root = this.MainDataSource.CreateNavigator();
                    root.SelectSingleNode("/my:myFields/my:debug", this.NamespaceManager).SetValue(ex.Message + ex.StackTrace);
                }
            }


    If you use it, mark it as useful.
    Thursday, May 28, 2009 8:57 PM

All replies

  • You can write code to reset form data to default on MyRessetButton_Clicked event

     public void MyRessetButton_Clicked(object sender, ClickedEventArgs e)
            {
                XPathNavigator elemStoreNumber = this.MainDataSource.CreateNavigator()
                        .SelectSingleNode("//my:StoreNumber", this.NamespaceManager);

                elemStoreNumber.SetValue(string.Empty);


               //  Write code to reset value for rest of the form fields


            }


    I am not sure if this the best solution though



    Regards
    Ashraf ul Islam
    Sharepoint Consultant

    Thursday, May 28, 2009 12:37 PM
  • Actually this is not as simple at it looks, the solutions depends on your datasource, an example could be

    mydata
    mydataset
    repeatingfolder
    datax
    datay

    if that is similar to your data you have to attach code to your form, 
    1.- add a button to your form and in properties select add custom code..
    2.- in VS do a selectsinglenode(mydata/mydataset/repeatingfolder , this.namespacemanager).xml 
    3.- put a break operation and debug the form so you can view the content of the node in xml in a quick view
    4.-copy the xml structure
    5.-exit the debug operation
    6.- put the xml  into a string variable in the form
    7.- modify the selectsinglenode(xpath, namespacemanager) to get the parent node
    8.- in the parent node set the inner xml used in 6.

    Example :

                    XPathNavigator root = MainDataSource.CreateNavigator();
                  
    
                    string xmlObjetivoTactico = @"
    	<my:URL xmlns:my='http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-09-26T18:40:28'>
    		<my:url>http://hildemoss/MyPictures/logosantander.jpg</my:url>
    		<my:url2>http://hildemoss/MyPictures/SantanderRed.jpg</my:url2>
    	</my:URL>
    	<my:debug xmlns:my='http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-09-26T18:40:28'></my:debug>
    ";
                 
                    
                    if (root.SelectSingleNode("/my:myFields", this.NamespaceManager) != null)
                    {
                        root.SelectSingleNode("/my:myFields", this.NamespaceManager).InnerXml = xmlObjetivoTactico;
                    }
                }
                catch (System.Exception ex)
                {
                    XPathNavigator root = this.MainDataSource.CreateNavigator();
                    root.SelectSingleNode("/my:myFields/my:debug", this.NamespaceManager).SetValue(ex.Message + ex.StackTrace);
                }
            }


    If you use it, mark it as useful.
    Thursday, May 28, 2009 8:57 PM