I'm trying to get a list of all available/non selected items in from a MultilistField
.
I know you can use this to get the selected items
applicationField.GetItems()
How do I go about getting the list of available items to use?
Thanks!
Sitecore Stack Exchange is a question and answer site for developers and end users of the Sitecore CMS and multichannel marketing software. It only takes a minute to sign up.
Sign up to join this communitySomething like this should do the trick:
// get the "Source" string from the template field
var sourceString = applicationField.InnerField.Source;
// get the item from which the field comes from
var currentItem = applicationField.InnerField.Item;
// get selected ids of selected items
var selectedItems = applicationField.TargetIDs;
using (new LanguageSwitcher(currentItem.Language))
{
// get all the items based on the "Source" string and item
var allItems = LookupSources.GetItems(currentItem, sourceString);
// filter out selected from all the items
var unselectedItems = allItems.Where(item => !selectedItems.Contains(item.ID));
}