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

Set focus in runtime ?

2 Answers 193 Views
MultiColumn ComboBox
This is a migrated thread and some comments may be shown as answers.
Per
Top achievements
Rank 1
Per asked on 26 Aug 2009, 01:25 PM
Hi!

I have a main form containing MDI forms.
When I load my MDI form (containing a multi column drop down control), I want the drop down control to have focus so I can start writing in it without first having to selected it.
(Im using a multi drop down control as a search input field)

Can this be done ?

Regards
Per

2 Answers, 1 is accepted

Sort by
0
Accepted
Deyan
Telerik team
answered on 26 Aug 2009, 04:23 PM
Hello Per,

Thanks for writing and for your question.

Yes, it is possible to set the focus on the RadMultiColumnComboBox when the MDI Child Form is shown so that you can immediately start typing. Take a look at the code snippets below:

public partial class Form1 : RadForm 
    { 
        public Form1() 
        { 
            InitializeComponent(); 
        } 
 
        protected override void OnLoad(EventArgs e) 
        { 
            base.OnLoad(e); 
 
            this.IsMdiContainer = true
            ComboMdiChild child = new ComboMdiChild(); 
            child.MdiParent = this
            child.Show(); 
            child.Shown += new EventHandler(child_Shown); 
        } 
 
        void child_Shown(object sender, EventArgs e) 
        { 
            ComboMdiChild child = sender as ComboMdiChild; 
 
            if (child != null
            { 
                child.ComboBox.Focus(); 
            } 
        } 
    } 

This is the code of my MDI Parent form. In the Load event of the parent I create an instance of the ComboMDIChild class which represents my MDI Child form. This class has a ComboBox property which exposes the RadMultiColumnComboBox control. I subscribe for the Shown event of the MDI Child and in its Event Handler I call the Focus method of the RadMultiColumnComboBox control.

Here is the code of the ComboMdiChild class:

public partial class ComboMdiChild : RadForm 
    { 
        public ComboMdiChild() 
        { 
            InitializeComponent(); 
        } 
 
 
        public RadMultiColumnComboBox ComboBox 
        { 
            get 
            { 
                return this.radMultiColumnComboBox1; 
            } 
        } 
    } 

I hope this is helpful.

Do not hesitate to write back if you need further assistance.

Regards,
Deyan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Per
Top achievements
Rank 1
answered on 27 Aug 2009, 05:58 AM
Perfect!
Just what I was looking for.
Thanks!

//Per
Tags
MultiColumn ComboBox
Asked by
Per
Top achievements
Rank 1
Answers by
Deyan
Telerik team
Per
Top achievements
Rank 1
Share this question
or