jbagley

PBControl casting issues

Discussion created by jbagley on Apr 4, 2013
Latest reply on Apr 5, 2013 by jbagley

Hello everyone,

 

I am trying to add a OptionButton to a processbook display using C#.  I can get the symbol to be created, but am having trouble casting the symbol as a PBControl afterwards. Originally I was trying to cast the result directly from adding a symbol, but had trouble so I followed Mathieu's advice on this post http://vcampus.osisoft.com/discussion_hall/add_in_microsoft_development/f/11/t/3919.aspx 

 

I cycled through the symbols and the results were the same as the ones below.

 
PBObjLib.Symbol radioButton;

            radioButton = sLICDisplay.Symbols.Add(PBObjLib.pbSYMBOLTYPE.pbSymbolControl, "Forms.OptionButton.1") as PBObjLib.Symbol;
            if (radioButton.Type == (int)PBObjLib.pbSYMBOLTYPE.pbSymbolControl)
            {
                PBSymLib.PBControl control = (PBSymLib.PBControl)radioButton;
                PBSymLib.PBControl control2 = radioButton as PBSymLib.PBControl;
            }

 The line 

 
PBSymLib.PBControl control = (PBSymLib.PBControl)radioButton;

causes a cast exception and the following line just gives a null.

 

 

 

The following code works in VBA behind procbook

 

 

 
Set a = Display1.Symbols.Add(pbSymbolControl, "Forms.OptionButton.1")

 where a is a PBControl.

 

 

 

Any suggestions on how I can grab onto to PBControl symbol so I can set the properties in C#

 

 

 

Thanks for any help

 

 

Outcomes