It is possible to set connections in SharePoint, but not so easy. Below is the code from my project.
At first we need some method to create transformer for consumers field and provider field:
private TransformableFilterValuesToParametersTransformer CreateTransformer(String consumerFieldName, String providerFieldName)
{
TransformableFilterValuesToParametersTransformer filterToParameterTransformer =
new TransformableFilterValuesToParametersTransformer();
// The private fields '_consumerFieldNames' and '_providerFieldNames' must be set for the web part connection to work.
// Having reflected the TransformableFilterValuesToParametersTransformer it seems that the only place this is set is within a
// nested wizard class (this seems to be the wizard that runs when the connection is created via the SharePoint UI) so although
// this is not pretty it looks to be the only way...
try
{
string[] _consumerFieldNames = new string[1];
_consumerFieldNames[0] = consumerFieldName;
FieldInfo conFld = typeof(TransformableFilterValuesToParametersTransformer).GetField("_consumerFieldNames", BindingFlags.Instance | BindingFlags.NonPublic);
conFld.SetValue(filterToParameterTransformer, _consumerFieldNames);
string[] _providerFieldNames = new string[1];
_providerFieldNames[0] = providerFieldName;
FieldInfo prvFld = typeof(TransformableFilterValuesToParametersTransformer).GetField("_providerFieldNames", BindingFlags.Instance | BindingFlags.NonPublic);
prvFld.SetValue(filterToParameterTransformer, _providerFieldNames);
}
catch
{
throw new Exception("Unexpected internal definition for 'TransformableFilterValuesToParametersTransformer'. Please amend private member access code.");
}
return filterToParameterTransformer;
}
Now create connection:
TransformableFilterValuesToParametersTransformer transformer = CreateTransformer("ConsumerFieldInternalName", "ProviderFieldInternalName");
ProviderConnectionPointCollection pcpc = mgr.GetProviderConnectionPoints(providerWebPart);
ConsumerConnectionPointCollection ccpc = mgr.GetConsumerConnectionPoints(consumerWebPart);
mgr.SPConnectWebParts(
providerWebPart, pcpc[0],
consumerWebPart,
ccpc[0],
transformer
);
mgr is SPLimitedWebPartManager instance of particular view page.
You can find more examples here:
http://social.msdn.microsoft.com/Forums/en/sharepointdevelopment/thread/3f960d66-af45-42ca-82d7-114de773213f
http://jsiegmund.wordpress.com/2010/05/28/sp2010-programmatically-creating-a-web-part-page-with-connected-webparts/