<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://www.infopathdev.com:443/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Code</title><link>https://www.infopathdev.com:443/forums/45.aspx</link><description /><dc:language>en</dc:language><generator>CommunityServer 2007 SP3 (Build: 31118.962)</generator><item><title>How to disable a custom toolbar button using C# code</title><link>https://www.infopathdev.com:443/forums/thread/38598.aspx</link><pubDate>Wed, 18 Feb 2009 22:41:17 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:38598</guid><dc:creator>KavithaY</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/38598.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=38598</wfw:commentRss><description>&lt;p&gt;Hi All,&lt;/p&gt;
&lt;p&gt;I am facing a problem with Disabling of a custom tool bar button. Actually i am making &lt;strong&gt;&amp;quot;Enabled&amp;quot; &lt;/strong&gt;property of&amp;nbsp;my custom tool bar button to &lt;strong&gt;&amp;quot;false&amp;quot;&lt;/strong&gt;. But it is not disabling. If i made &amp;quot;Visible&amp;quot; property of that toolbar button to &amp;quot;&lt;strong&gt;false&lt;/strong&gt;&amp;quot;, then it&amp;#39;s working means the control is in-visible. But my actual requirement is i should disable the button not as in-visible.&lt;/p&gt;
&lt;p&gt;Can any one please&amp;nbsp;help me. It&amp;#39;s very urgent. Thanks in advance.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;u&gt;Below is my template and code details:&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;In My Template manifest.xsn file, below is the code for my custom tool bar.&lt;/p&gt;
&lt;p&gt;&amp;lt;xsf:toolbar caption=&amp;quot;Custom ToolBar&amp;quot; name=&amp;quot;CustomToolbar&amp;quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;xsf:button name=&amp;quot;btnSaveToDatabase&amp;quot; icon=&amp;quot;SaveToDatabase.gif&amp;quot; tooltip=&amp;quot;Save To Database&amp;quot; showIf=&amp;quot;immediate&amp;quot;&amp;gt;&amp;lt;/xsf:button&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;xsf:button name=&amp;quot;btnConvertToWord&amp;quot; tooltip=&amp;quot;Show In Word&amp;quot; icon=&amp;quot;Word.gif&amp;quot;&amp;gt;&amp;lt;/xsf:button&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;xsf:button action=&amp;quot;btnRemoveApprover&amp;quot; caption=&amp;quot;Remove Approver&amp;quot; tooltip=&amp;quot;Remove Approver&amp;quot;&amp;gt;&amp;lt;/xsf:button&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;xsf:button action=&amp;quot;btnAddApprover&amp;quot; caption=&amp;quot;Add Approver&amp;quot; tooltip=&amp;quot;Add Approver&amp;quot;&amp;gt;&amp;lt;/xsf:button&amp;gt;&lt;br /&gt;&amp;lt;/xsf:toolbar&amp;gt;&lt;/p&gt;
&lt;p&gt;Based on the current position in the form i need to disable some of the custom tool basr buttons, say for example &amp;quot;btnRemoveApprover and btnAddApprover&amp;quot;. And these buttons i am using to Add/Delete a row to myApprovers table.&lt;/p&gt;
&lt;p&gt;To get the current selected section from the form i raised an OnContextChanged event.&lt;/p&gt;
&lt;p&gt;below is my code:&lt;/p&gt;&lt;font size="2"&gt;[&lt;/font&gt;&lt;font color="#008080" size="2"&gt;InfoPathEventHandler&lt;/font&gt;&lt;font size="2"&gt;(EventType=&lt;/font&gt;&lt;font color="#008080" size="2"&gt;InfoPathEventType&lt;/font&gt;&lt;font size="2"&gt;.OnContextChange)]&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; 
&lt;p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;public&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;void&lt;/font&gt;&lt;font size="2"&gt; OnContextChange(&lt;/font&gt;&lt;font color="#008080" size="2"&gt;DocContextChangeEvent&lt;/font&gt;&lt;font size="2"&gt; e)&lt;/font&gt;&lt;/p&gt;&lt;font size="2"&gt;{&lt;/font&gt;&lt;font size="2"&gt; 
&lt;p&gt;&lt;/font&gt;&lt;font color="#008080" size="2"&gt;CommandBars&lt;/font&gt;&lt;font size="2"&gt; objCommandBars = UnwrapCommandbarsObject((&lt;/font&gt;&lt;font color="#008080" size="2"&gt;ObjectWrapper&lt;/font&gt;&lt;font size="2"&gt;)thisXDocument.View.Window.CommandBars);&lt;/p&gt;&lt;/font&gt;&lt;font color="#008080" size="2"&gt;CommandBar&lt;/font&gt;&lt;font size="2"&gt; customToolBar = &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;null&lt;/font&gt;&lt;font size="2"&gt;;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; 
&lt;p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;try&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt;
&lt;p&gt;{&lt;/p&gt;customToolBar = objCommandBars[&lt;/font&gt;&lt;font color="#800000" size="2"&gt;&amp;quot;CustomToolBar&amp;quot;&lt;/font&gt;&lt;font size="2"&gt;];&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; 
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;catch&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt;
&lt;p&gt;{&lt;/p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;return&lt;/font&gt;&lt;font size="2"&gt;;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; 
&lt;p&gt;}&lt;/p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;if&lt;/font&gt;&lt;font size="2"&gt; (e.Context.nodeName != &lt;/font&gt;&lt;font color="#800000" size="2"&gt;&amp;quot;my:Approvers&lt;/font&gt;&lt;font color="#800000" size="2"&gt;&amp;quot;&lt;/font&gt;&lt;font size="2"&gt;) // my:Approvers is the section for adding/deleting approvers in my form.&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; 
&lt;p&gt;{&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt;
&lt;p&gt;customToolBar.Controls[3].Enabled = &lt;font color="#0000ff"&gt;false;&lt;/font&gt;&lt;/p&gt;customToolBar.Controls[4].Enabled = &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;false&lt;/font&gt;&lt;font size="2"&gt;;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; 
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;else&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;customToolBar.Controls[3].Enabled = &lt;font color="#0000ff"&gt;true;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;customToolBar.Controls[4].Enabled = &lt;font color="#0000ff" size="2"&gt;true&lt;/font&gt;&lt;font size="2"&gt;;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;&lt;/font&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Kavitha&lt;/p&gt;</description></item></channel></rss>