WebPart.GetToolParts Method

Determines which tool parts are displayed in the tool pane of the Web-based Web Part design user interface, and the order in which they are displayed.

Namespace:  Microsoft.SharePoint.WebPartPages
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: No

Syntax

'Declaration
Public Overridable Function GetToolParts As ToolPart()
'Usage
Dim instance As WebPart
Dim returnValue As ToolPart()

returnValue = instance.GetToolParts()
public virtual ToolPart[] GetToolParts()

Return Value

Type: []
An array of type ToolPart that determines which tool parts will be displayed in the tool pane. If a Web Part that implements one or more custom properties does not override the GetToolParts method, the base class method will return an instance of the WebPartToolPart class and an instance of the CustomPropertyToolPart class. An instance of the WebPartToolPart class displays a tool part for working with the properties provided by the WebPart base class. An instance of the CustomPropertyToolPart class displays a built-in tool part for working custom Web Part properties, as long as the custom property is of one of the types supported by that tool part. The supported types are: String, Boolean, Integer, DateTime, or Enum.

Remarks

When creating a custom Web Part that includes custom properties that require a custom tool part (an implementation of the ToolPart class), you must override the GetToolParts method to specify the list of custom tool parts in that are rendered inside the tool pane.

Examples

The following code example shows an overridden GetToolParts method.

' Gets the custom tool parts for this Web Part by overriding the
' GetToolParts method of the WebPart base class. You must implement
' custom tool parts in a separate class that derives from 
' Microsoft.SharePoint.WebPartPages.ToolPart. 
' Returns an array of references to ToolPart objects.

Public Overrides Function GetToolParts()As ToolPart()
    Dim toolParts(2) As ToolPart   
    Dim wptp As WebPartToolPart = New WebPartToolPart()
    Dim custom As CustomPropertyToolPart  = New CustomPropertyToolPart()
    toolparts(0) = wptp
    toolparts(1) = custom

    Return toolparts

End Function
/// <summary>
/// Gets the custom tool parts for this Web Part by overriding the
/// GetToolParts method of the WebPart base class. You must implement
/// custom tool parts in a separate class that derives from 
/// Microsoft.SharePoint.WebPartPages.ToolPart. 
/// </summary>
/// <returns>An array of references to ToolPart objects.</returns>

public override ToolPart[] GetToolParts()
{
    ToolPart[] toolparts = new ToolPart[2];
    WebPartToolPart wptp = new WebPartToolPart();
    CustomPropertyToolPart custom = new CustomPropertyToolPart();
    toolparts[0] = wptp;
    toolparts[1] = custom;

    return toolparts;
}

See Also

Reference

WebPart Class

WebPart Members

Microsoft.SharePoint.WebPartPages Namespace