IT tutorials
 
Technology
 

InfoPath with SharePoint 2010 : Dynamically Populate a Repeating Table - Clear Previous Entries

1/26/2014 8:19:13 PM
- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019

1. Clear Previous Entries

Scenario/Problem:You need to clear previous entries.

Solution:Loop through the repeating table and clear the values.

If you preview the form at this point, you will notice that every time you select a value from the selection drop-down, the repeating table is populated with more and more entries (along with a blank row at the top). You therefore need to clear any previous entries before the repeating table is populated. Place the code listed in Listing 1 somewhere before the while loop.

Listing 1. Clear Previous Entries
//Clear previous entries
XPathNavigator rTable = MainDataSource.CreateNavigator();
XPathNodeIterator tableRows =
rTable.Select("/my:myFields/my:group1/my:groupRepeat",
NamespaceManager);
if (tableRows.Count > 0)
{

for (int i = tableRows.Count; i > 0; i--)
{
XPathNavigator reTable = MainDataSource.CreateNavigator();
XPathNavigator reTableRows =
reTable.SelectSingleNode("/my:myFields/my:group1/my:groupRepeat[" + i
+ "]", NamespaceManager);
reTableRows.DeleteSelf();
}
}

2. What Does the Final Solution Look Like?

When all the code has been entered into the method properly, previewing the form populates the repeating table based on the selection in the drop-down, as shown in Figure 1.

Figure 1. Changing the selection populates the repeating table.

Listing 2 shows the full code listing for the changed method.

Listing 2. Fully Changed Method
public void selection_Changed(object sender, XmlEventArgs e)
{

//Namespace variable
string myNamespace = NamespaceManager.LookupNamespace("my");

//Clear previous entries
XPathNavigator rTable = MainDataSource.CreateNavigator();
XPathNodeIterator tableRows =
rTable.Select("/my:myFields/my:group1/my:groupRepeat",
NamespaceManager);
if (tableRows.Count > 0)
{


for (int i = tableRows.Count; i > 0; i--)
{
XPathNavigator reTable =
MainDataSource.CreateNavigator();
XPathNavigator reTableRows =

reTable.SelectSingleNode
("/my:myFields/my:group1/my:groupRepeat[" + i + "]",
NamespaceManager);
reTableRows.DeleteSelf();
}
}

//Secondary data source setup
DataSource ds = DataSources["Offices"];
XPathNavigator domNav = ds.CreateNavigator();
XPathNodeIterator rows = domNav.Select("/dfs:myFields/
dfs:dataFields/d:SharePointListItem_RW", NamespaceManager);


//Loop through the secondary data source
while (rows.MoveNext())
{
string office =
rows.Current.SelectSingleNode("d:Title",
NamespaceManager).Value.ToString();
string region = rows.Current.SelectSingleNode("d:Region",
NamespaceManager).Value.ToString();
string id =
rows.Current.SelectSingleNode("d:ID",
NamespaceManager).Value.ToString();

//Populate the repeating table
using (XmlWriter writer =

MainDataource.CreateNavigator().SelectSingleNode("/my:myFields/
my:group1", NamespaceManager).AppendChild())
{
writer.WriteStartElement("groupRepeat", myNamespace);
writer.WriteElementString("field1", myNamespace, office);
writer.WriteElementString("field2", myNamespace, region);
writer.WriteElementString("field3", myNamespace, id);
writer.WriteEndElement();
writer.Close();
}

}

}
 
Others
 
- InfoPath with SharePoint 2010 : Dynamically Populate a Repeating Table - Loop Through the Secondary Data Source , Populate the Repeating Table
- InfoPath with SharePoint 2010 : Dynamically Populate a Repeating Table - Create a Namespace Variable, Access the Secondary Data Source
- InfoPath with SharePoint 2010 : Dynamically Populate a Repeating Table - Create a Changed Event Method
- InfoPath with SharePoint 2010 : Dynamically Populate a Repeating Table - Set Up the Initial Form
- Windows 7 : Managing Application Compatibility (part 6) - Installing and Configuring the Application Compatibility Toolkit
- Windows 7 : Managing Application Compatibility (part 5) - Using the Application Compatibility Toolkit - Compatibility Administrator , Internet Explorer Compatibility Test Tool
- Windows 7 : Managing Application Compatibility (part 4) - Using the Application Compatibility Toolkit - Application Compatibility Manager
- Windows 7 : Managing Application Compatibility (part 3) - Using the Program Compatibility Troubleshooter , Suppressing Compatibility Controls Using Group Policy
- Windows 7 : Managing Application Compatibility (part 2) - Evaluating Application Incompatibility Solutions - Using Compatibility Modes
- Windows 7 : Managing Application Compatibility (part 1) - Creating an Application Inventory
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
Technology FAQ
- Is possible to just to use a wireless router to extend wireless access to wireless access points?
- Ruby - Insert Struct to MySql
- how to find my Symantec pcAnywhere serial number
- About direct X / Open GL issue
- How to determine eclipse version?
- What SAN cert Exchange 2010 for UM, OA?
- How do I populate a SQL Express table from Excel file?
- code for express check out with Paypal.
- Problem with Templated User Control
- ShellExecute SW_HIDE
programming4us programming4us