Setting focus on ComboBox with C#

Posted by: stevehochreiter on 10 September 2017, 11:37 am EST

  • Posted 10 September 2017, 11:37 am EST

    I'm trying to set the focus on a combo box and when I do, the combo box text is not selected.  If I tab to the combo box the text is selected.  Is therea a way I can highlight the text when I set the focus by ComboBox1.Focus()?

  • Replied 10 September 2017, 11:37 am EST

    Hello,


    Attached is a sample that shows how to give the C1ComboBox focus in C# and in JavaScript.  I prefer the JavaScript approach, but that is entirely up to you.


    Let me know if you have any questions about the sample.


    Thanks,


    -Raleigh


    2011/03/246587_WebApplication1.zip
  • Replied 10 September 2017, 11:37 am EST

     


    Thanks for the reply.  I added 3 items to the combo box for testing.


    When tabbing from the text box to the combo box the text is highlighted.  If you type a character the highlighted text is replaced.



    This is what I want to accomplish with the set focus.


    With the set focus code the combo box text is not highlighted.  Is there a way to do this?

  • Replied 10 September 2017, 11:37 am EST

    Hi Steve,


    I just added an item to my ComboBox, and it seems to work exactly the way you want.  Can you try the following version and see if works the way you expect?  


    http://tinyurl.com/48codbc


    Also, what browser are you using?


    Thanks,


    -Raleigh

  • Replied 10 September 2017, 11:37 am EST


    I'm using IE ver 8.0.7600.16385.  I copied your zip files to my project.  It does not highlight the text in the combo box.


    I selected the first entry, moved the cursor to the text box and here's a screen shot after pressing the C# button.


     

  • Replied 10 September 2017, 11:37 am EST

    Hi Steve,


    If you change code to set focus on the TextBox, you will see the same behavior in IE; however, this seems to work as expected in Firefox.  I am not sure if there is anything that can be done about this, but I will see what I can find.


    Thanks,


    -Raleigh

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels