This is a migrated thread and some comments may be shown as answers.

TextBoxElement in Ribbon

4 Answers 127 Views
RibbonBar
This is a migrated thread and some comments may be shown as answers.
Jerome Prunera-Usach
Top achievements
Rank 1
Jerome Prunera-Usach asked on 19 Nov 2010, 04:03 PM
Hello,

I have a form with a RadRibbonBar and a RadGridView.
Within the toolbar I have programmatically added a RadTextBoxElement (and a button) in order to search through the grid.
Everything is working perfectly well except when I try to implement the CTRL+F shortcut. The event do get fired and I am able to catch the requested action, but then I cannot get the textbox to focus.

I have tried both mytextboxelement.TextBoxItem.Focus() and mytextboxelement.Focus() with no success.

private void searchKeyDown(object sender, KeyEventArgs e)
{
    if(e.KeyCode == Keys.F3)
        btnSearch_Click(null, null);
    else if (e.KeyCode == Keys.F && e.Modifiers == Keys.Control)
    {
        RadTextBoxElement txt = (RadTextBoxElement)this.radRibbonBarButtonGroup1.Items[0];
        txt.TextBoxItem.Focus();
    }
}

Any idea if I'm doing something wrong or if there is a problem ?

Thank you,

  • OS Information : Windows XP x64 (version 2003) SP2
  • Telerik : RadControls for WinForms 2010.3 10.1109
  • Microsoft Visual Studio 2008
  • .NET 3.5

4 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 20 Nov 2010, 02:41 PM
Hello Jerome,

I'd like to try this and help you with your issue. Please can you tell me, the keydown event that you are using below, what is it the KeyDown event of?

Let me know and I'll do my best to help
Thanks
Richard
0
Accepted
Richard Slade
Top achievements
Rank 2
answered on 20 Nov 2010, 05:01 PM
Hello again Jerome,

Ok, i've been having a look at this for you, and it's ended up to be quite simple. In the code below, I have a RadRibbonBar and a RadGridView on the form. I've added one tab to the RadRibbonBar, and one group to the tab. In the group, I have then added a RadTextBoxElement during Form Load and wired up the KeyDown events of each of the items on the form.

The magic line to get the cursor to flash in the textbox is:
txt.TextBoxItem.HostedControl.Focus();


Here is the whole thing..
using System;
using System.Windows.Forms;
using Telerik.WinControls.UI;
  
namespace RadControlsWinFormsApp1
{
    public partial class Form1 : Form
    {
  
        public Form1()
        {
            InitializeComponent();
        }
  
        private void Form1_Load(object sender, EventArgs e)
        {
            RadTextBoxElement textboxElment = new RadTextBoxElement();
            this.radRibbonBarGroup1.Items.Add(textboxElment);
            this.radRibbonBar1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.SearchKeyDown);
            this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.SearchKeyDown);
            this.radGridView1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.SearchKeyDown);
        }
  
        private void SearchKeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F3)
                MessageBox.Show("Here");
            else if (e.KeyCode == Keys.F && e.Modifiers == Keys.Control)
            {
                RadTextBoxElement txt = (RadTextBoxElement)this.radRibbonBarGroup1.Items[0];
                txt.TextBoxItem.Text = "";
                // Focus on the hosted control, not the textbox item
                txt.TextBoxItem.HostedControl.Focus();
            
        }
  
    }
}

Hope this helps, but let me know if you need more information. Please remember to mark as answer if this has provided the answer for you.
Thanks
Richard
0
Richard Slade
Top achievements
Rank 2
answered on 22 Nov 2010, 02:33 PM
Hello,

How did you get on with this? If it helped, please remember to mark as answer. If you need more assistance, please just let me know.
thanks
Richard
0
Jerome Prunera-Usach
Top achievements
Rank 1
answered on 22 Nov 2010, 02:49 PM
Hello Richard,

txt.TextBoxItem.HostedControl.Focus();

That single line of code did the trick.

Thank you
Tags
RibbonBar
Asked by
Jerome Prunera-Usach
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Jerome Prunera-Usach
Top achievements
Rank 1
Share this question
or