C # Calling focus on text field in SelectedIndexChange event of Listview loses focus on event completion

I have a list, and when I click on an element, it raises the SelectedIndexChange event, in this case I want to set focus on the text field, so I call:

this.ActiveControl = theTextBoxControl;

I see the focus switch in the text box for a second, but the focus returns to the list as soon as the event ends. Any ideas how to fix this?

+3
source share
1 answer

you could create and set a flag to true, for example needToFocusTextBox. And then do the following in the onFocus event in the ListView.

if (needToFocusTextBox)
    this.ActiveControl = theTextBoxControl;

onFocus SlectedIndexChange. , onfocus

+1

All Articles