TextBox on Ribbon Control

Dec 17, 2010 at 7:11 AM

Okay, my first post...  First of all, this ribbon control is awesome!  I'm glad I didn't waste atleast hundreds of dollars on some other website for some rip-off version.  Anyway, super good job.

Now, down to business.  Is there anyway for the ribbon to host a TextBox control?

According to http://msdn.microsoft.com/en-us/library/dd940497(v=VS.85).aspx, there doesn't seem to be.  Normally, I would just say okay and move on, but I find it really hard to believe for a control of this caliber to not have a TextBox.

Not that it matters, but incase you're wondering, I'm updating/upgrading an older VB .Net app and replacing two toolstrips with the Ribbon.  One of the ToolStrips had a TextBox which the user could use for database searches.  I really don't want to make the user click a button to open a search window.  I already have something like this for advanced searches.  The ToolStrip TextBox is more of a quick search, and it's used a lot.  Plus, I think one of the purposes of the Ribbon was so there would be fewer dialogs.

Any suggestions would be highly appreciated.


PS. Sorry for posting this twice.  I posted in the wrong place the first time.

Dec 18, 2010 at 8:22 AM

Thanks for your complements.

Unfortunately, there is no way to host a TextBox control in the ribbon.
This is a limitation of the underlying Windows Ribbon Framework.

That being said, you can use a ComboBox with free text inserting (IsEditable=True).
Check-out my post about using ComboBox in the ribbon for more details: http://blogs.microsoft.co.il/blogs/arik/archive/2009/10/21/windows-ribbon-for-winforms-part-8-combobox.aspx

If you do go the ComboBox way, I suggest that you actually use the drop down feature, e.g. add recent searches to the combo.


Dec 22, 2010 at 6:43 PM

Thanks for the quick response, Arik.  That's a great idea (using the ComboBox).  I think it'll be much better than the TextBox.

Now, following your suggestion.  I have three questions.  Keep in mind, I did check out your Ribbon ComboBox post (which was very helpful btw), but I'm still having some trouble.

1) It seems there is no KeyPress/KeyDown event.  Is there any possible way to achieve this?  The way my old TextBox worked that I'm replacing is I gave the user the option of searching as they type, or after Enter is pressed.  So, I need to know whenever a key is typed and also test to see if it was the Enter key. (see next question).

2) If it's possible to achieve what I'm hoping to do in question 1, how can I test each character to see if the Enter key was pressed.  What I'm familiar with when it comes to the KeyPress or KeyDown event for the Winforms ComboBox is as follows.  Can I do something similar with the Ribbon ComboBox?

If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Return) Then '// e as System.Windows.Forms.KeyPressEventArgs
If e.KeyCode = Keys.Enter Then '// e As System.Windows.Forms.KeyEventArgs
     ' do something
End If

3) How can I check if the ComboBox already contains a value?
When Enter is pressed in the ComboBox, I'm adding the ComboBox StringValue to the drop down as you suggested to record previous searches, but I can't figure out how to check if the StringValue already exists.  I don't want duplicates.  What I've been use to doing with the standard WinForms ComboBox is as follows.  Is there anything equivalent?

If ComboBox1.Items.IndexOf("Some string value.") = -1 Then
If Not ComboBox1.Items.Contains("Some string value.") Then
     ' add item to ComboBox
End If

Thanks for your help and patience.  You're probably light-years ahead of me as a programmer.  I hope I'm not pushing it with 3 questions. :)

Dec 27, 2010 at 8:04 PM

Okay, nevermind question #3 (How to check if ComboBox already contains a value).  I just decided to store each ComboBox.StringValue in a List(Of String) and use its contains method.  I then clear the Ribbon ComboBox using the Clear() method of RibbonComboBox, and then loop through and add each string from my List(Of String).

I still need a solution for question 1, and 2.  In addition, I have one more question (should be my last).

After pressing Enter in the ComboBox and ExecuteEvent is triggered, the ComboBox loses focus.  Is it possible to maintain focus on the ComboBox, or even return focus to it?


Thanks again.

Dec 27, 2010 at 8:35 PM

There is no KeyDown/KeyUp event for the combobox.

Generally speaking, I've exposed in my wrapper everything the windows ribbon framework has to offer.
So if it's not in the wrapper class, it doesn't exists. WYSIWYG.

There is no way to control the focus of the ribbon controls.