Adding a Custom Column to a VDF Grid


As I mentioned a few articles ago, the VDF has the concept of client properties.  On top of that, the VDF gives you the ability to add your own.  The main advantage here is that it gives you a column of your very own in the VDF grid.  Beyond that, most of the work is up to you.  You need to set the value.  If you want to persist the data, that’s also up to you.


Perhaps it’s best if I show a quick example.  Let’s create a property called “my prop def”, and set values based on a counter that I increment.

 

Step 1: Define a class the implements IPropertyExtensionProvider.

IPropertyExtensionProvider can do a lot of things.  Here I’m using it to supply a client property definition to the VDF.  I’m also using it to provide the values to that property when the VDF asks for them.

classMyPropertyProvider : IPropertyExtensionProvider

{

    PropertyDefinition m_myPropDef;

    long m_counter = 1;

 

    public MyPropertyProvider()

    {

        m_myPropDef = newPropertyDefinition("myPropDef");   

    }

 

    publicvoid DecoratePropertyDefinitions(…)

    {

        // not needed in this example.

    }

 

    publicIEnumerable<PropertyDefinition> GetCustomPropertyDefinitions()

    {

        return m_myPropDef.ToSingleArray();

    }

 

    publicvoid PostGetPropertyValues(…)

    {

        // not needed in this example.

    }

 

    publicvoid PreGetPropertyValues(
          
Connection
vltConn,
          
IEnumerable<IEntity
> entities,
          
PropertyDefinitionDictionary propDefs,

           PropertyValues resultValues,
          
PropertyValueSettings settings)

    {

           

        foreach (var entity in entities)

        {

            foreach (var propDef in propDefs.Values)

            {

                // ingore other properties

                if (propDef.SystemName != m_myPropDef.SystemName)

                    continue;

 

                // set the value for our custom property.

                resultValues.SetValue(newPropertyValue(

                      entity, propDef, m_counter.ToString()));

                m_counter++;

            }

        }

    }

 

    publicstring[] SupportedEntityClasses

    {

        get { returnnull; }

    }

}

 

Step 2: Register your provider.

MyPropertyProvider myProvider = newMyPropertyProvider();

VDF.Vault.Library.PropertyExtensionRegistration.
AddPropertyExtensionProvider(myProvider);

 

Step 3: Enjoy.

You can now use the column in any of your UI that uses the VDF.  Even if a VDF grid doesn’t explicitly set the column, the property shows up in the list when the user goes to customize the columns.

If your app is a Vault Explorer 2014 plug-in, your custom property is not available in the main grid or any of the default tabs.  This is because those grids are not true VDF grids.  (Fun fact: The file browser on the Attach command does used the VDF grid, so you can see your custom properties there)



Comments

2 responses to “Adding a Custom Column to a VDF Grid”

  1. What if I want to define a custom property that was displayed as a 16×16 icon in VaultBrowserControl ?
    Thank you.

  2. I’ve never done it myself, but my guess is that you set the value to an ImageInfo object.
    I have an article on reading the different property types. So that should be helpful in knowing how to write them.
    http://justonesandzeros.typepad.com/blog/2014/03/reading-values-through-the-propertymanager.html

Leave a Reply to Doug RedmondCancel reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading