How do I populate this programmatically?

Jul 8, 2010 at 10:53 AM

Firtly, this is a fab control and does exactly what I need it to!!!  Just have a query about its usage!

I am setting up a new filtered lookup field on a list, and I need to populate it with the selected items from a normal SharePoint Lookup field which this is replacing.  I am using this with the view filter option and allowing multiple values to be selected.

Can you give any guidance on how to do this?  My lookup and filtered lookup fields allow for multiple values, and I've tried using various methods to get the data from one to the other.

The SharePoint lookup is using an SPFieldLookupValueColletion, and it appears from the source code that the MultipleFilteredLookupControl is using this (in the get and set of Value).  But there does not seem to be any method to programmatically add items to the list or assign the value.  Any I try either result in an error or the code runs and nothing is updated!

Does anyone have any example code on how to populate the selected values in a Filtered Lookup programmatically (C# or VB)?

Thanks loads!


Jan 20, 2011 at 4:42 PM

Did you ever get a reply, or figure this out?  I tried:

$newHospital = new-Object Microsoft.SharePoint.SPFieldLookupValue($ID, $hospital)
$item["Hospital"] = $newHospital   <-- This is the filtered lookup field

in Powershell, but it didn't work; no errors, just didn't update the value.  If someone comes up with a solution, please post.  Thanks.