Populating InfoPath Drop Down List Box with SharePoint Fields Choice
Populate InfoPath drop-down programmatically from Sharepoint Field Choice
Download Infopath Form at here
Designing and coding infopath
- Article 1: How to code C-Sharp on infopath form 2010
- Article 2: How to set the value of a Field in Infopath
- Article 3: How to set value of a field from sharepoint list
- Article 4: Populating InfoPath Drop Down List Box with SharePoint List Lookup Data
- Article 5: Populating InfoPath Drop Down List Box with SharePoint Fields Choice
- Article 6: Deploy an InfoPath 2010 Form with Managed Code to a Browser Enabled Sharepoint Document Library
Download Infopath Form at here
Designing and coding infopath
Open Infopath | Design user interface follows as
Go to File => Form Options => Programming
Form template code language: C#
Go to File => Form Options => Security and Trust
Configure follows as:
Ads not by this site
Ads not by this site
Go to Tab Developer | click to Loading Event ribbon
Right click to myFields | Add
Ads not by this site
Name: GroupStatus
Type: Group
Check to Repeating
Ads not by this site
Right click to GroupStatus | Add
Ads not by this site
Name: Displayname
Continue Right click to GroupStatus | Add then input Name: Value
Ads not by this site
Ads not by this site
Right click to DropdownList “Country” | Drop-Down List Box Properties…
At List box choices------------------------------
Check to radio button “Get choice from fields in this from”, then click to Entries, select value follows as
Add reference to Microsoft.sharepoint.dll
Ads not by this site
Ads not by this site
Using using Microsoft.SharePoint;
Add method AddStatus (); to FormEvents_Loading
Paste this method to below FormEvents_Loading method public void AddStatus ()
using Microsoft.Office.InfoPath;
using System;
using System.Xml;
using System.Xml.XPath;
using Microsoft.SharePoint;
namespace SetValueToDropdownListInfoPathFromChoiceField
{
public partial class FormCode
{
// NOTE: The following procedure is required by Microsoft InfoPath.
// It can be modified using Microsoft InfoPath.
public void InternalStartup()
{
EventManager.FormEvents.Loading += new LoadingEventHandler(FormEvents_Loading);
}
public void FormEvents_Loading(object sender, LoadingEventArgs e)
{
AddStatus();
}
public void AddStatus()
{
try
{
SPSite site = new SPSite("http://win-67038mbkel7");
SPWeb web = site.OpenWeb();
SPList list = web.Lists["Tasks"];
SPFieldMultiChoice spFieldMultiChoice = (SPFieldMultiChoice)list.Fields["Status"];
XPathNavigator nav = this.CreateNavigator().SelectSingleNode("/my:myFields/my:GroupStatus",
this.NamespaceManager);
for (int item = 0; item < spFieldMultiChoice.Choices.Count; item++)
{
XPathNavigator newNode = null;
newNode = nav.Clone();
newNode.SelectSingleNode("/my:myFields/my:GroupStatus/my:Displayname",
this.NamespaceManager).
SetValue(spFieldMultiChoice.Choices[item].ToString());
newNode.SelectSingleNode("/my:myFields/my:GroupStatus/my:Value",
this.NamespaceManager).
SetValue(spFieldMultiChoice.Choices[item].ToString());
nav.InsertAfter(newNode);
newNode = null;
}
nav.DeleteSelf();
nav = null;
}
catch
{
}
}
}
}
Build project then click F5, result as below
Ads not by this site
Comments
Post a Comment