One stumbling block for developers coming up to speed on InfoPath is that the SDK documentation leads you to the edge of the XML cliff and then goes mysteriously quiet. For web developers who have programmed applications with the MSXML SDK for manipulating XML this isn’t a problem – they brought their parachute with them and happily jump off. For others, this can be a little intimidating.
Here’s a good way to get started manipulating the XML DOM directly – let’s add “Move Up” / “Move Down” buttons to a Repeating Table so you can re-order the items.
First off, let’s build the view:
At this point, you’re thinking “5 and 6???”
(Sneaky, huh? Glyphs from this font are used by Windows to render all sorts of UI elements like the Minimize/Maximize Window buttons. This is a handy way to avoid having to use images for simple things like arrows.)
Now that we have it looking pretty, let’s add the event handlers for the buttons. We’ll build on the logic from this blog entry to figure out which instance of the buttons was clicked.
Sub MoveUp_OnClick(eventObj)
' Write your code here
Dim oItem, oParent, oPrevious
Set oItem = eventObj.Source
Set oParent = oItem.parentNode
Set oPrevious = oItem.previousSibling
If Not ( oPrevious Is Nothing ) Then
oParent.removeChild oItem
oParent.insertBefore oItem, oPrevious
End If
End Sub
The logic here is straightforward:
Sub MoveDown_OnClick(eventObj)
Dim oItem, oParent, oNext
Set oNext = oItem.nextSibling
If Not ( oNext Is Nothing ) Then
oParent.removeChild oNext
oParent.insertBefore oNext, oItem
The logic here is similar:
Almost done – let’s just use a little Conditional Formatting to disable the buttons when the item is the first or last in the list:
Now try it out.
As an aside, this was the author’s first foray into VBScript. Although I cut my teeth in Applesoft BASIC I’ve done most of my programming in C-style languages (C, C++, C#, Perl, Java). Did I do anything silly?
PingBack from http://websitescripts.247blogging.info/infopath-team-blog-move-upmove-down/
Can someone provide me with an equivalent of this in C# for InfoPath 2010, browser enabled form.
Thanks