This documentation is archived and is not being maintained.

WebPart.GetToolParts Method

Windows SharePoint Services 3

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)

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.

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.

The following code example shows an overridden GetToolParts method.

/// <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;