I am using Infopath 2007 and vb.
I have a dataset
Aliases Y/N
AliasesGroup (repeating)
Aliases
I want the user to answer Y/N to the Aliases Y/N prompt and if the answer is Yes then display the Aliases. This works fine.
If Aliases are already present and the User changes the Y/N prompt to N I prompt the user on the changing event to see whether they really want to delete the Aliases.
If they say no then I rollback the change - this works fine
If they say yes - they really want to delete the Aliases I try to set the value of the first one present to "" and delete the rest. In both cases I get the error Operation is not valid, because of the current state of the object. How do I find out what is the state of the object ? Is there a better way to do this ? - My code is below
Public Sub AliasesYN_Changing(ByVal sender As Object, ByVal e As XmlChangingEventArgs)
' Ensure that the constraint you are enforcing is compatible
' If you are changing the alias to No and Aliases already exist prompt userIf e.OldValue = True And e.NewValue = False Then
Dim reply As DialogResult = MessageBox.Show("This will delete the existing Aliases", "Do you want to continue", MessageBoxButtons.OKCancel)
If reply = DialogResult.Cancel Then
e.CancelableArgs.Cancel = True
e.CancelableArgs.Message = "The change has been rolled back"
e.CancelableArgs.MessageDetails = "Changes have been rolled back, because they will be overwritten by changes in the Directory next time the contacts are checked"
Else
Dim grp As String = "/my:AliasesGroup"
Dim fld As String = "/my:AliasesGroup/my:Aliases"
Dim nav As XPathNavigator
Dim itgroup As XPathNodeIterator nav = e.Site.CreateNavigator.SelectSingleNode(grp, NamespaceManager)
itgroup = nav.Select(fld, NamespaceManager)
Dim norecs As Integer = itgroup.Count
Dim mov As Boolean = itgroup.MoveNext
While mov = True
itgroup.Current.SetValue("")
itgroup.MoveNext()
While mov = True
itgroup.Current.DeleteSelf()
itgroup.MoveNext()
End While
End While
End If
End If
End Sub