Geeks With Blogs
Path Notes of a Kodefu Master blog

When creating a designer for Visual Studio, you may want to allow editing in the properties pane. This took me a while to figure out how to do, because the terminology wasn't quite what I expected it to be. Here's how I accomplished this task.

The window pane that hosts the designer implements IVsWindowPane. This interface contains a method called SetSite, which will provide a pointer to an object that implements IServiceProvider. I instantiate a ServiceProvider and assign this to a ServiceProvider property on the editor.

public int SetSite(IOleServiceProvider psp)
    decisionTableEditor.ServiceProvider =
new ServiceProvider(psp);
return VSConstants.S_OK;

Inside the code for DecisionTableEditor, I have a private method called ShowProperties. This method will take a SelectionContainer that it will pass to the TrackSelection service. The service is obtained using the ServiceProvider's GetService method. The container is passed into the TrackSelection's OnSelectChange method. It is important to note that you can't change this to pass in the array of objects (either as an array or as params) and assign it to the selection containers SelectedObjects because it interrogates the the type of array in deciding what properties to show in the panel (which will be none for object).

private void ShowProperties(SelectionContainer container)
var track = ServiceProvider.GetService(typeof(STrackSelection)) as ITrackSelection;
if (track != null)

When you want to call ShowProperties, you create a SelectionContainer and set its SelectedObjects property to an array of the object you wish to show. If the properties window needs to be cleared, passing in null for the container will do the trick.

SelectionContainer selectionContainer = null;

if (ColumnIndex >= 0)
    selectionContainer =
new SelectionContainer();

    selectionContainer.SelectedObjects =
new[] { DecisionTable.Columns[ColumnIndex] };


The next step is deciding what to show. By default, public properties will show up. If they're read-only, they will be read-only in the Properties pane. In the class definition for the objects you wish to show in the Properties pane, you can assign attributes to be more descriptive. These attributes are located in the System.ComponentModel namespace. The most important is probably the BrowsableAttribute, as it allows you to hide properties from the Properties pane. DescriptionAttribute and CategoryAttribute are useful as well, but you will need to deep dive System.ComponentModel if you want to get the full power of the Properties pane.

Posted on Monday, June 1, 2009 7:05 PM Kodefu | Back to top

Comments on this post: Edit Object in Properties Pane

# re: Edit Object in Properties Pane
Requesting Gravatar...

Excelent article, well writen and fine and clean code

Left by web development company on Aug 18, 2009 1:15 PM

Your comment:
 (will show your gravatar)

Copyright © Chris Eargle | Powered by: