C# Calling focus on text box in SelectedIndexChange event of Listview loses focus on event completion
I have a listview and when I click on an item, it calls the SelectedIndexChange event, in that event I want to set the focus on a textbox so I call:
this.ActiveControl = theTextBoxControl;
I can see the focus switch to the text box for a split second but focus returns to the listview as soon as the event completes. Any idea开发者_开发技巧s how to fix this?
you could probably create and set a flag to true, eg: needToFocusTextBox
. And then do the following in the onFocus event of the ListView.
if (needToFocusTextBox)
this.ActiveControl = theTextBoxControl;
Alternatively you could assign the onFocus handler in your SlectedIndexChange event. Then remove it once you have handled onfocus
精彩评论