none
VB: using the textchanged event with an XML RibbonEditBox RRS feed

  • Question

  • Hi there,

    I'm trying to implement a search-like function in the ribbon using a RibbonEditBox - but am running into a problem that someone else seems to have had in the past:

    http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/4852476f-2b1c-401c-ad82-a1fa596d88f0/

    Essentially, I have a callback firing through the editbox's onChange event, which works perfectly to capture an enter key press, but it also fires when the editbox loses focus. Ideally, I'd only like the event to fire when the user presses the return key and do nothing when the control loses focus.

    Here's my ribbon's xml:

    <customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="Ribbon_Load">
      <ribbon>
        <tabs>
          <tab id="Tab" label ="Tab">
            <group id="Searchbox" label="Search">
              <labelControl id="myLabel1" label=" " />
              <editBox id="editBox1" sizeString="WWWWWWWWWWWWWWWWWWWWWWWWW" tag="searchstr" onChange="dothis" />
              <labelControl id="myLabel2" label=" " />
              <labelControl id="myLabel3" label=" " />
              <button id="Button6" onAction="tester" size="normal" imageMso="InstantSearch" tag="searchbutton"/>
            </group>
          </tab>
        </tabs>
      </ribbon>
    </customUI>

    And here's the callback:

    Sub dothis(control As Microsoft.Office.Core.IRibbonControl, text As String)
    
            MsgBox("hello world", MsgBoxStyle.OkOnly, "test")
    
    End Sub

    Any pointers would be greatly appreciated! I'm not sure exactly how I would implement the suggestion made at the tail end of the thread I referenced earlier.

    Sunday, June 3, 2012 9:54 AM

Answers

  • last suggestion in that thread is for someone using Ribbon designer, and you are using ribbon xml - maybe try to migrate your code to ribbon designer by hand (remember that you can nnot have both ribbon xml and designer in single add-in).

    As for sticking with ribbon xml - i would store somewhere last searched phrase and when control looses focus and fires onChange event - compare if value there changed to the one stored - if not, do not spin up searching. It should work.

    Monday, June 4, 2012 7:59 AM
  • if user sees results that are ok for him, he stops entering text into editbox, so when this control looses focus you are already displaying results for text that is there. But if you want full custom solution then i guess you should rather move to custom task pane where you control everything.

    Monday, June 4, 2012 9:10 AM

All replies

  • last suggestion in that thread is for someone using Ribbon designer, and you are using ribbon xml - maybe try to migrate your code to ribbon designer by hand (remember that you can nnot have both ribbon xml and designer in single add-in).

    As for sticking with ribbon xml - i would store somewhere last searched phrase and when control looses focus and fires onChange event - compare if value there changed to the one stored - if not, do not spin up searching. It should work.

    Monday, June 4, 2012 7:59 AM
  • Thank you for the suggestion - that's the direction I'd been headed in, but it ultimately comes down to more of a user experience issue than a practical one - I think a user clicking out of the editbox shouldn't trigger a search fullstop. For instance, I might have results already displayed and realise that (despite having started to refine my query) what I wanted was already there, except the second I move out of the control to get it, the onchange event will fire. Ideally, it would be as simple as: the user presses return, the search function fires. And I'm loath to hook the keyboard to catch a return key press..

    On the XML front, I've got to stick with it to get the getVisible callback, which - as far as I'm aware - isn't supported in the ribbon designer. Sigh.


    • Edited by chinaski2 Monday, June 4, 2012 8:50 AM
    Monday, June 4, 2012 8:50 AM
  • if user sees results that are ok for him, he stops entering text into editbox, so when this control looses focus you are already displaying results for text that is there. But if you want full custom solution then i guess you should rather move to custom task pane where you control everything.

    Monday, June 4, 2012 9:10 AM