disabling custom toolbar at startup

B

Brühno

Hello everybody,

in our Infopath form we have a few toolbars and we want to decide in
the startup code which of these toolbars should be displayed.
Unfortunately in all known startup events (OnLoad, OnSwitchView,
OnContextChange, ...) we cannot access the custom toolbars, I think
because they are not created yet at these points.
If we start our toolbar configuration routine manually after the form
has loaded (using a button), it can access and disable the toolbars as
expected.
How can we access the custom toolbars at form startup?

Thanks in advance,

Daniel Scholz
 
F

Franck Dauché

Hi,

If you want to Show/Hide built-In toolbars or basic custom toolbars, you can
call code from the OnLoad Event. If you are dealing with "advanced" custom
toolbars (View dependent for example), then you may need to use the
OnContextChange event to call your code as the SwitchView Event needs to be
fired before you can do anything.
What are you trying to do? Can you post some code if you need assistance?

Franck Dauché
 
B

Brühno

Hello Franck, thank you for you help offer :)

here is our code:

toolbar definition in manifest.xsl:
....
<xsf:toolbar caption="EditView" name="Toolbar_EditView">
<xsf:button name="SaveAndQuit" caption="Speichern und Beenden"
icon="3"></xsf:button>
<xsf:button name="PrintView" caption="Druckansicht"
icon="230"></xsf:button>
<xsf:button name="Cancel" caption="Abbrechen"
icon="231"></xsf:button>
</xsf:toolbar>
....

Our toolbar config routine contains the following code to
disable/enable the toolbar:

....
BindingFlags MethodFlags = BindingFlags.GetProperty |
BindingFlags.DeclaredOnly | BindingFlags.Public |
BindingFlags.Instance;
ObjectWrapper commandBars =
(ObjectWrapper)thisApplication.ActiveWindow.CommandBars;
CommandBar cmdbEdit= (CommandBar)commandBars.InvokeByName("Item",
MethodFlags, new object[] {"EditView"}, null);
cmdbEdit.Enabled= false;
.....

if we run this code in the OnLoad event, the following exception is
thrown:

System.Reflection.TargetInvocationException
Ein Aufrufziel hat einen Ausnahmefehler verursacht.(*TRANSLATION: A
calling target has thrown an exception*)
at System.RuntimeType.InvokeDispMethod(String name, BindingFlags
invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers,
Int32 culture, String[] namedParameters)
at System.RuntimeType.InvokeMember(String name, BindingFlags
invokeAttr, Binder binder, Object target, Object[] args,
ParameterModifier[] modifiers, CultureInfo culture, String[]
namedParameters)
at System.Type.InvokeMember(String name, BindingFlags invokeAttr,
Binder binder, Object target, Object[] args, CultureInfo culture)
at
Microsoft.Office.Interop.InfoPath.SemiTrust.ObjectWrapper.InvokeByName(String
name, BindingFlags invokeAttr, Object[] args, CultureInfo culture)
at
Microsoft.Office.Interop.InfoPath.SemiTrust.ObjectWrapper.InvokeByName(String
name, BindingFlags invokeAttr, Object[] args, CultureInfo culture)
.....


if we execute the same code manually using a button from within the
loaded form, it executes without problems.
Where is the problem?

Waiting hopefully for you answer,

Best regards,

Daniel
 
F

Franck Dauché

Hi,

OK I see what your problem is. You are mixing 2 ways to handle toolbars.
You created a custom toolbar by modifying the Manifest.xsf (which means that
is now hard coded in your form), and you are trying to reach it by code as if
it was an Office toolbar.
To be able to manipulate your toolbar by code as you wish to do, you need to
remove the lines of code in your manifest, and you need to add an office
toolbar.

Instead of using
http://msdn.microsoft.com/library/d...html/ipsdkDisplayCustomToolbar_HV01083303.asp

Try to use this reference to create your toolbar
http://msdn.microsoft.com/library/d...foPathCustomizingInfoPathMenusandToolbars.asp

Hope that it helps you.

Franck Dauché


Brühno said:
Hello Franck, thank you for you help offer :)

here is our code:

toolbar definition in manifest.xsl:
....
<xsf:toolbar caption="EditView" name="Toolbar_EditView">
<xsf:button name="SaveAndQuit" caption="Speichern und Beenden"
icon="3"></xsf:button>
<xsf:button name="PrintView" caption="Druckansicht"
icon="230"></xsf:button>
<xsf:button name="Cancel" caption="Abbrechen"
icon="231"></xsf:button>
</xsf:toolbar>
....

Our toolbar config routine contains the following code to
disable/enable the toolbar:

....
BindingFlags MethodFlags = BindingFlags.GetProperty |
BindingFlags.DeclaredOnly | BindingFlags.Public |
BindingFlags.Instance;
ObjectWrapper commandBars =
(ObjectWrapper)thisApplication.ActiveWindow.CommandBars;
CommandBar cmdbEdit= (CommandBar)commandBars.InvokeByName("Item",
MethodFlags, new object[] {"EditView"}, null);
cmdbEdit.Enabled= false;
.....

if we run this code in the OnLoad event, the following exception is
thrown:

System.Reflection.TargetInvocationException
Ein Aufrufziel hat einen Ausnahmefehler verursacht.(*TRANSLATION: A
calling target has thrown an exception*)
at System.RuntimeType.InvokeDispMethod(String name, BindingFlags
invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers,
Int32 culture, String[] namedParameters)
at System.RuntimeType.InvokeMember(String name, BindingFlags
invokeAttr, Binder binder, Object target, Object[] args,
ParameterModifier[] modifiers, CultureInfo culture, String[]
namedParameters)
at System.Type.InvokeMember(String name, BindingFlags invokeAttr,
Binder binder, Object target, Object[] args, CultureInfo culture)
at
Microsoft.Office.Interop.InfoPath.SemiTrust.ObjectWrapper.InvokeByName(String
name, BindingFlags invokeAttr, Object[] args, CultureInfo culture)
at
Microsoft.Office.Interop.InfoPath.SemiTrust.ObjectWrapper.InvokeByName(String
name, BindingFlags invokeAttr, Object[] args, CultureInfo culture)
.....


if we execute the same code manually using a button from within the
loaded form, it executes without problems.
Where is the problem?

Waiting hopefully for you answer,

Best regards,

Daniel
 
B

Brühno

Many, many thanks, Franck!!!! Your hint has helped us solving our
problem, I am so happy :eek:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top