Set focus in runtime ?

3 posts, 1 answers
  1. Per
    Per avatar
    116 posts
    Member since:
    Jan 2008

    Posted 26 Aug 2009 Link to this post

    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. Answer
    Deyan
    Admin
    Deyan avatar
    2038 posts

    Posted 26 Aug 2009 Link to this post

    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.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Per
    Per avatar
    116 posts
    Member since:
    Jan 2008

    Posted 27 Aug 2009 Link to this post

    Perfect!
    Just what I was looking for.
    Thanks!

    //Per
Back to Top