Tuesday, March 10, 2009

Configuring a SharePoint WebPart as both a Consumer and Provider for the same interface

Recently I’ve been coding a web part that shows a sql query inside a SPGridView and wanted to set it up so it could be a connection provider (ConnectionProvider) as well as a connection consumer (ConnectionConsumer).

For some reason, when I set it up this way the Connections menu used to configure the inbound and outbound connections was greyed out when I had both, but worked if I commented out either one.

It seems that there is an optional argument named “id” for both the ConnectionProvider and ConnectionConsumer decorators and when I provided this argument it started working. It seems there is a default id if you don’t specify it and they must have the same default id.

My code now looks something like this:

#Region "IWebPartRow Provider"
<ConnectionProvider("RowProvider", "DataViewRowProvider")> _
Public Function GetConnectionInterface() As IWebPartRow
Return New DataViewWebPart()
End Function

Public Sub GetRowData(ByVal callback As RowCallback) _
Implements IWebPartRow.GetRowData
callback(oGrid.SelectedRow)

End Sub

Public ReadOnly Property Schema() As _
ComponentModel.PropertyDescriptorCollection Implements IWebPartRow.Schema
Get
Return TypeDescriptor.GetProperties(oView)
End Get
End Property
#End Region
#Region "IWebPartRow Consumer"
<ConnectionConsumer("Row", "DataViewRowConsumer")> _
Public Sub SetConnectionInterface(ByVal provider As IWebPartRow)
_provider = provider
End Sub

#End Region

No comments: