Hi everybody,
I have a problem with programatically inserting a row in InfoPath repeating table. I have 7 fields in my data source like field1, field2, field3, field4, field5, Copyfield4, Copyfield5. Of these 7 fields first five are in the repeating node and the remaining two are global (like " dfs:myFields/my:Copyfield4”). I am showing only three fields in the repeating table (field1, field2, field3) and the other two are not shown in the repeating table, which are hidden.
Here I am showing Copyfield4, Copyfield5 are under the repeating table, where one is drop down list box and the other is a normal text box. My case is I will enter data into field1, field2, field3 (which are the fields in the repeating table) and Copyfield4, Copyfield5 (which are under the repeating table) and I will click a button in the repeating table. Based on that click I am transferring the data from Copyfield4, Copyfield5 (which are under the repeating table) to field4, field5 (Transferring is working fine). At the same time I am inserting a new and empty row (which will have the same fields as in the first row).
Here my problem is while adding the new row below the current row, hidden fields (field4, field5) of newly entered row are getting data from the above row. If I click the add button with out entering data in Copyfield4, Copyfield5 it should show an error message that these fields are empty. But it wasn't showing that because the hidden fields are getting the data from the above row. But after inserting the row I am forcing all the fields to nulls. I have some more fields, they are working fine when I make them nulls but only these two are not working. I am getting this repeating node from SAP developers, the only similarity between those fields was both are character fields of size 10.
I am having the problem only with these two fields. One of these two fields is loaded based on the other field (which is somewhere in the form) selection.
Here is my repeating node, which we got from SAP developers.
/dfs:myFields/dfs:queryFields/tns: METHOD1/STRUCTURE /item (In this XPath item is the repeating node.)
My code for adding a new row below the current row is,
XPathNavigator xFill= MainDataSource.CreateNavigator();
string myNamespace = NamespaceManager.LookupNamespace("");
using (XmlWriter writer = MainDataSource.CreateNavigator().SelectSingleNode("/dfs:myFields/dfs:queryFields/tns:METHOD1/STRUCTURE", NamespaceManager).AppendChild())
{
writer.WriteStartElement("item", myNamespace);
writer.WriteElementString("field1", myNamespace, "");
writer.WriteElementString("field2", myNamespace, "");
writer.WriteElementString("field3", myNamespace, "");
writer.WriteElementString("field4", myNamespace, "");
writer.WriteElementString("field5", myNamespace, "");
writer.WriteEndElement();
writer.Close();
xFill.SelectSingleNode("/dfs:myFields/my:Copyfield4",NamespaceManager).SetValue("");
xFill.SelectSingleNode("/dfs:myFields/my:Copyfield5",NamespaceManager).SetValue("");
}
Here i am forcefully clearing all the fields in the repeating table as well as under the repeating table fields.
This is the code i am using to forcefully make null values of the new row fields using the below two lines in the above code.
writer.WriteElementString("field4", myNamespace, "");
writer.WriteElementString("field5", myNamespace, "");
Here I am forcefully clearing all the fields under the repeating table with the following two lines in the above code.
xFill.SelectSingleNode("/dfs:myFields/my:Copyfield4",NamespaceManager).SetValue("");
xFill.SelectSingleNode("/dfs:myFields/my:Copyfield5",NamespaceManager).SetValue("");
Of these above two fields one is dropdown list box and the other is a text box. The field4, field5 are only taking the values from the above row, all the other fields in the repeating table are working fine. I don't understand what's wrong with these two fields. They are only taking above rows value if I don’t enter anything in Copyfield4, Copyfield5. If enter any data in Copyfield4 and Copyfield5 its taking the freshly entered data.
If I confused u with my scenario I am glad to explain again and again. This is very important for my further form design.
Thanks in Advance,
Kalyan.