title: Visio VSTO: InvalidateControl not working on focus change
body: <p>Using Visio 2013 I faced a strange behaviour of <code>InvalidateControl</code> method (or Visio VSTO mechanism). My idea is to change selected item in <code>dropDown1</code> whenever I change its item value in <code>editBox1</code>.</p>
  <p>It works when I change text and hit Enter or click on free area on ribbon tab, <em>but in does not work if I click on <code>editBox2</code> making it active (focused)</em>. In the latter case DropDown gets updated (and callbacks get called) only if I click on DropDown itself afterwards.</p>
  <p>I've also noticed that DropDown gets updated whenever Visio window loses focus ang gains it again (for instance if I switch to another aplication and back), so my other hacky idea was to force Visio to update its UI in some  way (for instance via WinAPI like <code>RedrawWindow</code> etc), unfortunaly I don't know well all the stuff with WinAPI.</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;customUI xmlns=&quot;http://schemas.microsoft.com/office/2009/07/customui&quot; onLoad=&quot;Ribbon_Load&quot;&gt;
    &lt;ribbon&gt;
      &lt;tabs&gt;
        &lt;tab idMso=&quot;TabAddIns&quot;&gt;
          &lt;group id=&quot;group3&quot; label=&quot;Test&quot;&gt;
            &lt;box id=&quot;box1&quot;&gt;
              &lt;editBox id=&quot;editBox1&quot;
                       getText=&quot;GetText&quot;
                       onChange=&quot;EditBoxTextChange&quot;
                       sizeString=&quot;WWW&quot; /&gt;
              &lt;editBox id=&quot;editBox2&quot;
                       getText=&quot;GetText&quot;
                       sizeString=&quot;WWW&quot; /&gt;
              &lt;dropDown id=&quot;dropDown1&quot;
                        getSelectedItemIndex=&quot;GetSelectedItemIndex&quot;
                        getItemCount=&quot;GetItemCount&quot;
                        getItemLabel=&quot;GetItemLabel&quot;
                        sizeString=&quot;WWW&quot; /&gt;
            &lt;/box&gt;
          &lt;/group&gt;
        &lt;/tab&gt;
      &lt;/tabs&gt;
    &lt;/ribbon&gt;
  &lt;/customUI&gt;
  </code></pre>
  <p>Ribbon class</p>
  <pre><code>public class Ribbon1 : Office.IRibbonExtensibility
      {
          private Office.IRibbonUI ribbon;
  
          string[] data = { &quot;1&quot;, &quot;2&quot;, &quot;3&quot;, &quot;4&quot;, &quot;5&quot; };
          int selectedIndex;
  
          public Ribbon1()
          {
          }
  
          #region IRibbonExtensibility Members
  
          public string GetCustomUI(string ribbonID)
          {
              return GetResourceText(&quot;FosusTest.Ribbon1.xml&quot;);
          }
  
          #endregion
  
          #region Ribbon Callbacks
          //Create callback methods here. For more information about adding callback methods, visit http://go.microsoft.com/fwlink/?LinkID=271226
  
          public void Ribbon_Load(Office.IRibbonUI ribbonUI)
          {
              this.ribbon = ribbonUI;
          }
  
          public string GetText(IRibbonControl control)
          {
              if (control.Id == &quot;editBox1&quot;)
              {
                  return &quot;1&quot;;
              }
              else
              {
                  return &quot;2&quot;;
              }
          }
  
          public void EditBoxTextChange(IRibbonControl control, string text)
          {
              for (var i = 0; i &lt; data.Count(); ++i)
              {
                  if (data[i] == text)
                  {
                      selectedIndex = i;
                      ribbon.InvalidateControl(&quot;dropDown1&quot;);
                      break;
                  }
              }
          }
  
          public int GetSelectedItemIndex(IRibbonControl control)
          {
              return selectedIndex;
          }
  
          public int GetItemCount(IRibbonControl control)
          {
              return data.Count();
          }
  
          public string GetItemLabel(IRibbonControl control, int index)
          {
              return data[index];
          }
  
          #endregion
  
      }
  </code></pre>
  <p><a href="https://github.com/schmidt9/FocusTest" rel="nofollow noreferrer">Example project</a> Visual Studio 2013 / Visio 2013</p>