Question

well, I've been trying to create a new custom property in a shape and I somehow managed, however, when I try to change the name of the Label I can only write numbers. Could you provide me how to do it in C# or maybe in VB so I can get a hint?

My code is:

//First I create the row
shape.AddRow((short)VisSectionIndices.visSectionProp,(short) (iRow + 1), (short) VisRowTags.visTagDefault);

//And now I try to write the Label
shape.CellsSRC[(short)VisSectionIndices.visSectionProp, (short)(iRow + 1), (short)VisCellIndices.visCustPropsLabel].Result[VisUnitCodes.visNoCast] = 123456789

However, when the Result method only accepts boolean as input, and I don't know how to write a string overthere...

Thanks in advance!

Was it helpful?

Solution

I've also been looking into how to set the string value of a custom shape data property. Just got it to work like this:

var newPropertyValue = "cool new value";
tstShape.Cells["Prop.SuperCustomPropertyName"].FormulaU = "\"" + newPropertyValue + "\"";

Disclaimer that I am no expert with Visio Automation, but it works in my circumstance. I'm using visio 2010 and studio 2010 Hopefully it helps.

OTHER TIPS

You can use the following code:

private void AddCustomProperty(Microsoft.Office.Interop.Visio.Shape shape, string PropertyName, String propertyValue)
        {
            try
            {

                short customProps = (short)VisSectionIndices.visSectionProp;      

                short rowNumber = shape.AddRow(customProps, (short)VisRowIndices.visRowLast, (short)VisRowTags.visTagDefault);

                shape.CellsSRC[customProps, rowNumber, (short)VisCellIndices.visCustPropsLabel].FormulaU = "\"" + PropertyName + "\"";

                shape.CellsSRC[customProps, rowNumber, (short)VisCellIndices.visCustPropsValue].FormulaU = "\"" + propertyValue + "\"";


            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show("Error: " + e.Message);
            }

        }

The Result isn't meant to be read/write. What you want to do is set the FormulaU property of the cell to the label name. The Result property just calculates the formula for the cell and returns the result, which is why you have to provide a unit for the return value.

Also, the AddRow method returns the actual row number for the added row, which isn't necessarily the row you specified. For shapesheet sections with nameable rows, like the Custom Properties section, Visio may ignore the row you requested and just stick it at the bottom.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top