Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I have following code

public partial class Configuration : UserControl
{
public Configuration()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(Configuration_Loaded);
}

void Configuration_Loaded(object sender, RoutedEventArgs e)
{
combobox.Focus();
}
}

When usercontrol is loaded i want to set focus to combobox. I did same in the code. but problem is that like textbox we can not see focus on combobox. Is it bug of wpf control ?

Thanks in advance
Posted

I don't know what exactly you want, however by reading your code
- which works properly btw -
I guess you want to put a different look on the combobox, when it's focused.

You can achieve this, by using the FocusVisualStyle-Property.
 
Share this answer
 
C#
public partial class Configuration : UserControl
{
public Configuration()
{
InitializeComponent();
combobox.Focus();
}
}

combobox name should be give 1
 
Share this answer
 
Comments
midnight_ 24-Jul-13 6:36am    
Using focus methods in the constructor is wrong!
Since at this point the control is not visible, there is no control where you can set the focus.
You need a visible element with an id to set focus on.

So the code of the inquirer is correct, using it in at the "Loaded"-event.
public partial class Configuration : UserControl
{
public Configuration()
{
InitializeComponent();
combobox.Focus();
}
}

combobox Tab Index should be give 1
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900