Repeating table and behind code - InfoPath Dev Sign in | Join | Help in Newbie Questions InfoPath (Entire Site) InfoPath Dev InfoPath Dev is dedicated to bringing you the information and tools you need to be successful in your Microsoft Office InfoPath development projects. Home Blogs Forums Photos Downloads InfoPath Dev » InfoPath » Newbie Questions » Repeating table and behind code Repeating table and behind code Last post 11-13-2008 11:06 PM by swathip. 7 replies. Page 1 of 1 (8 items) Sort Posts: Oldest to newest Newest to oldest Previous Next 11-12-2008 03:17 AM davex Joined on 11-04-2008 Posts 8 Repeating table and behind code Reply Contact Hi, I have this code that calculates the amount of days between two dates (DateDebut and DateFin) which are parts of a repeating table. The calcul is made when the second date field (DateFin) is changed. Until there, everything just work fine. My main problem is that when I add another row the my repeating table, I don't know the names of the new controls created by the action of adding a new row to the repeating table ! Is there any way to increment an ID field name or anything ? The code which calcultes the amount of days between the two dates field. These are named "DateEnd" and "DateFin". How can I "call" these once a new row is created ?public void DateFin_Changed(object sender, XmlEventArgs e) { XPathNavigator MainData2 = MainDataSource.CreateNavigator(); DateTime dt1 = MainData2.SelectSingleNode("/my:DemandeConge/my:Conges/my:DateDebut", NamespaceManager).ValueAsDateTime;DateTime dt2 = MainData2.SelectSingleNode("/my:DemandeConge/my:Conges/my:DateFin", NamespaceManager).ValueAsDateTime; System.TimeSpan span = dt2.Subtract(dt1);double final = span.TotalDays; string final2 = final.ToString();MainData2.SelectSingleNode("/my:DemandeConge/my:Conges/my:Total", NamespaceManager).SetValue(final2); } THANKS A LOT ! 11-12-2008 05:33 AM In reply to swathip Joined on 10-30-2007 India Posts 487 Re: Repeating table and behind code Mark as Not AnswerMark as Answer... Reply Contact Hi,Every time you are calculating the first rows field’s difference. You can call the newly inserted “DateEnd” using e.Site.SelectSingleNode("../my:DateEnd",NamespaceManager) Use the following code.public void field2_Changed(object sender, XmlEventArgs e){ XPathNavigator MainData2 = MainDataSource.CreateNavigator();if (e.Site.SelectSingleNode("../my:field2",NamespaceManager).Value == ""){return;}DateTime dt1 = e.Site.SelectSingleNode("../my:field1",NamespaceManager).ValueAsDateTime; DateTime dt2 = e.Site.SelectSingleNode("../my:field2",NamespaceManager).ValueAsDateTime;System.TimeSpan span = dt2.Subtract(dt1); double final = span.TotalDays;string final2 = final.ToString(); e.Site.SelectSingleNode("../my:field3", NamespaceManager).SetValue(final2); }Here my:field1 -> my:DateDebutmy:field2 -> my:DateFinmy:field3 -> my:Total Swathipwww.ggktech.com 11-12-2008 07:06 AM In reply to davex Joined on 11-04-2008 Posts 8 Re: Repeating table and behind code Mark as Not AnswerMark as Answer... Reply Contact Hi Shiva, Thanks for you explanation which I understand, I think ! Unfortunately, it doesn't work completely. I think your code is ok because the calcul is still done but for me, it's the XmlEvents for the DateFin (second date field) in my code that doesn't work because it checkes EventManager.XmlEvents["/my:DemandeConge/my:Conges/my:DateFin"].Changed instead of the last inserted one as e.Site.EventManager.XmlEvents["/my:DemandeConge/my:Conges/my:DateFin"].Changed But how to translate this into a correct code to get the last DateFin event field ? Here's the full code : using Microsoft.Office.InfoPath; using System; using System.Xml; using System.Xml.XPath; using System.Collections.Generic; using System.Text; using System.Globalization;namespace Demande_Conge { public partial class FormCode {public void InternalStartup() {EventManager.FormEvents.Loading += new LoadingEventHandler(FormEvents_Loading);EventManager.XmlEvents["/my:DemandeConge/my:Conges/my:DateFin"].Changed += new XmlChangedEventHandler(DateFin_Changed); }public void FormEvents_Loading(object sender, LoadingEventArgs e) { XPathNavigator MainData = MainDataSource.CreateNavigator();MainData.SelectSingleNode("/my:DemandeConge/my:IDDemande", NamespaceManager).SetValue(MainData.SelectSingleNode("/my:DemandeConge/my:Employe", NamespaceManager).Value + "_" + DateTime.Now.ToShortDateString()); }public void DateFin_Changed(object sender, XmlEventArgs e) {XPathNavigator MainData2 = MainDataSource.CreateNavigator(); if (e.Site.SelectSingleNode("/my:DemandeConge/my:Conges/my:DateFin",NamespaceManager).Value == "") {return; } DateTime dt1 = e.Site.SelectSingleNode("/my:DemandeConge/my:Conges/my:DateDebut",NamespaceManager).ValueAsDateTime; DateTime dt2 = e.Site.SelectSingleNode("/my:DemandeConge/my:Conges/my:DateFin",NamespaceManager).ValueAsDateTime; System.TimeSpan span = dt2.Subtract(dt1); double final = span.TotalDays; string final2 = final.ToString(); e.Site.SelectSingleNode("/my:DemandeConge/my:Conges/my:Total", NamespaceManager).SetValue(final2); } //Here my:field1 -> my:DateDebutmy:field2 -> my:DateFinmy:field3 -> my:Total } } Thanks ! 11-12-2008 09:22 PM In reply to swathip Joined on 10-30-2007 India Posts 487 Re: Repeating table and behind code Mark as Not AnswerMark as Answer... Reply Contact Hi, DateFin_Changed(..) event will be called every time when the DateFin field value is changed. The field name should not be changed when we insert a new row. But if we use MainData2.SelectSingleNode("/my:DemandeConge/my:Conges/my:DateFin", NamespaceManager), in the changed event, every time the first row’s DateFin is considered. If we want to know the present inserted row DateFin, then we can refer that as e.Site. There is no event for last DateFin event field. But we can get the last DateFin using MainData2.SelectSingleNode("/my:DemandeConge/my:Conges[position() = last()]/my:DateFin", NamespaceManager). Can you give more details about what is your actual requirement? Swathipwww.ggktech.com 11-13-2008 03:23 AM In reply to davex Joined on 11-04-2008 Posts 8 Re: Repeating table and behind code Mark as Not AnswerMark as Answer... Reply Contact Hi Swathip ! Thanks again for the time you are giving to me. Below, you will find a concrete example of what I'm doing. First row acts as I want. The calcul is well made once "DateFin" field is changed. The problem is that when I insert a new row, nothing happens in the "Total" field of this new row when the "DateFin" field is changed. But if I replace the code that affects the value of the "Total" field by MainData2.SelectSingleNode("/my:DemandeConge/my:Conges[position() = last()]/my:Total", NamespaceManager).SetValue(final2); instead of e.Site.SelectSingleNode("/my:DemandeConge/my:Conges/my:Total", NamespaceManager).SetValue(final2); everytime I insert a row, the "Total" field will get the value of the first row "Total" field... I hope I'm clear with this. I put you the public void DateFin_Changed() code below :public void DateFin_Changed(object sender, XmlEventArgs e) { XPathNavigator MainData2 = MainDataSource.CreateNavigator(); if (e.Site.SelectSingleNode("/my:DemandeConge/my:Conges/my:DateDebut", NamespaceManager).Value == "") { return; }DateTime dt1 = e.Site.SelectSingleNode("/my:DemandeConge/my:Conges/my:DateDebut", NamespaceManager).ValueAsDateTime;DateTime dt2 = e.Site.SelectSingleNode("/my:DemandeConge/my:Conges/my:DateFin",NamespaceManager).ValueAsDateTime; System.TimeSpan span = dt2.Subtract(dt1); double final = span.TotalDays; string final2 = final.ToString(); // e.Site.SelectSingleNode("/my:DemandeConge/my:Conges/my:Total", NamespaceManager).SetValue(final2);MainData2.SelectSingleNode("/my:DemandeConge/my:Conges[position() = last()]/my:Total", NamespaceManager).SetValue(final2); } THANKS A LOT ! 11-13-2008 03:53 AM In reply to swathip Joined on 10-30-2007 India Posts 487 Re: Repeating table and behind code Mark as Not AnswerMark as Answer... Reply Contact Hi, Every time you are setting the first row total value. You can solve your problem by altering some code which is formatted as BOLD. public void DateFin_Changed(object sender, XmlEventArgs e) {XPathNavigator MainData2 = MainDataSource.CreateNavigator(); if (e.Site.SelectSingleNode("../my:DateDebut", NamespaceManager).Value == "") {return;}DateTime dt1 = e.Site.SelectSingleNode("../my:DateDebut", NamespaceManager).ValueAsDateTime;DateTime dt2 = e.Site.SelectSingleNode("../my:DateFin",NamespaceManager).ValueAsDateTime; System.TimeSpan span = dt2.Subtract(dt1); double final = span.TotalDays; string final2 = final.ToString(); // e.Site.SelectSingleNode("/my:DemandeConge/my:Conges/my:Total", NamespaceManager).SetValue(final2);e.Site.SelectSingleNode("../my:Total", NamespaceManager).SetValue(final2);} Swathipwww.ggktech.com 11-13-2008 04:41 AM In reply to davex Joined on 11-04-2008 Posts 8 Re: Repeating table and behind code Mark as Not AnswerMark as Answer... Reply Contact Man, it finally works, thanks to you !!! Can you tell me what you have exactly done ? Does "../my:DateFin" mean that we "play" with the control of a specific row of a repeating table ? THANKS A LOT, I couldn't achieve it without you. 11-13-2008 11:06 PM In reply to swathip Joined on 10-30-2007 India Posts 487 Re: Repeating table and behind code Mark as Not AnswerMark as Answer... Reply Contact Hi,I am glad to hear that you got it.Here e.Site means the current row on which we are specifically doing the changes. e.Site.SelectSingleNode("../my:DateDebut", NamespaceManager)Here e.Site means the DateFin node of the row changed. So, e.Site.SelectSingleNode("..” , NamespaceManager) will bring the parent node e.Site(in this case i.e. Congess Node)And e.Site.SelectSingleNode("../my:DateDebut", NamespaceManager)Gives the DateDebut node of the row changed. Swathipwww.ggktech.com Page 1 of 1 (8 items) Copyright © 2003-2019 Qdabra Software. All rights reserved.View our Terms of Use.
Hi,
I have this code that calculates the amount of days between two dates (DateDebut and DateFin) which are parts of a repeating table.
The calcul is made when the second date field (DateFin) is changed. Until there, everything just work fine.
My main problem is that when I add another row the my repeating table, I don't know the names of the new controls created by the action of adding a new row to the repeating table ! Is there any way to increment an ID field name or anything ?
The code which calcultes the amount of days between the two dates field. These are named "DateEnd" and "DateFin". How can I "call" these once a new row is created ?
{
System.
}
THANKS A LOT !
Hi Shiva,
Thanks for you explanation which I understand, I think !
Unfortunately, it doesn't work completely. I think your code is ok because the calcul is still done but for me, it's the XmlEvents for the DateFin (second date field) in my code that doesn't work because it checkes
EventManager.XmlEvents["/my:DemandeConge/my:Conges/my:DateFin"].Changed
instead of the last inserted one as
e.Site.EventManager.XmlEvents["/my:DemandeConge/my:Conges/my:DateFin"].Changed
But how to translate this into a correct code to get the last DateFin event field ?
Here's the full code :
using
Thanks !
DateFin_Changed(..) event will be called every time when the DateFin field value is changed. The field name should not be changed when we insert a new row. But if we use MainData2.SelectSingleNode("/my:DemandeConge/my:Conges/my:DateFin", NamespaceManager), in the changed event, every time the first row’s DateFin is considered. If we want to know the present inserted row DateFin, then we can refer that as e.Site.
There is no event for last DateFin event field. But we can get the last DateFin using MainData2.SelectSingleNode("/my:DemandeConge/my:Conges[position() = last()]/my:DateFin", NamespaceManager).
Hi Swathip !
Thanks again for the time you are giving to me.
Below, you will find a concrete example of what I'm doing. First row acts as I want. The calcul is well made once "DateFin" field is changed. The problem is that when I insert a new row, nothing happens in the "Total" field of this new row when the "DateFin" field is changed.
But if I replace the code that affects the value of the "Total" field by MainData2.SelectSingleNode("/my:DemandeConge/my:Conges[position() = last()]/my:Total", NamespaceManager).SetValue(final2); instead of e.Site.SelectSingleNode("/my:DemandeConge/my:Conges/my:Total", NamespaceManager).SetValue(final2); everytime I insert a row, the "Total" field will get the value of the first row "Total" field...
I hope I'm clear with this. I put you the public void DateFin_Changed() code below :
Every time you are setting the first row total value. You can solve your problem by altering some code which is formatted as BOLD.
Man, it finally works, thanks to you !!!
Can you tell me what you have exactly done ? Does "../my:DateFin" mean that we "play" with the control of a specific row of a repeating table ?
THANKS A LOT, I couldn't achieve it without you.