C# 在 Listview 的 SelectedIndexChange 事件中调用文本框焦点失去事件完成焦点
我有一个列表视图,当我单击一个项目时,它会调用 SelectedIndexChange 事件,在该事件中我想将焦点设置在文本框上,所以我调用:
this.ActiveControl = theTextBoxControl;
我可以看到焦点瞬间切换到文本框,但事件完成后焦点立即返回到列表视图。有什么想法如何解决这个问题吗?
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 ideas how to fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以创建一个标志并将其设置为 true,例如:
needToFocusTextBox
。然后在ListView的onFocus事件中执行以下操作。或者,您可以在 SlectedIndexChange 事件中分配 onFocus 处理程序。然后在处理完 onfocus 后将其删除
you could probably create and set a flag to true, eg:
needToFocusTextBox
. And then do the following in the onFocus event of the ListView.Alternatively you could assign the onFocus handler in your SlectedIndexChange event. Then remove it once you have handled onfocus