简体   繁体   English

单击ListView时TextBox获得焦点

[英]TextBox receiving focus when clicking on ListView

I'm struggling to make a custom autocomplete style control for my application using a list view. 我正在努力使用列表视图为我的应用程序创建自定义自动完成样式控件。 In one form, the custom control is working as expected, however in another, when clicking on the ListView, rather than the ListViewItem being selected, the first TextBox in the form is selected instead. 在一种形式中,自定义控件按预期方式工作,但是在另一种形式中,单击ListView而不是选择ListViewItem时,而是选择了表单中的第一个TextBox。

Rather than clog up the question with a wall of code, here is the code for the AutoCompleteListView . 这里不是用一堆代码来阻塞问题,而是使用AutoCompleteListView的代码。

Here is an image of the form. 这是表格的图像。 Items are redacted due to data protection: 由于数据保护,已删除项目: 表格图片

Also, here is a .gif showing the behaviour of the form. 另外, 是显示表单行为的.gif文件。 What I'm doing in the aformentioned gif is attempting to click on the first item within the ListView, however, as I do that, focus changes to the first text box in the form. 我在上述gif中所做的是尝试单击ListView中的第一项,但是,当我这样做时,将焦点更改为表单中的第一个文本框。 This same behaviour occurs when clicking on any item, in any of the 3 text boxes. 单击三个文本框中的任何一个中的任何项目时,也会发生相同的行为。

I have attempted to trace the events using RuntimeFlow to watch as events fire, but it has not provided any clarity as to what is actually happening. 我试图使用RuntimeFlow跟踪事件,以观察事件的触发,但是它并未提供关于实际情况的任何清晰信息。 If anyone could point me in the right direction, that'd be greatly appreciated. 如果有人能指出我正确的方向,那将不胜感激。

My first guess is in ItemClick you are setting visibility to false, which means something else in the form needs focus, ie the textbox. 我的第一个猜测是在ItemClick中将可见性设置为false,这意味着表单中的其他内容需要关注,例如文本框。 So do a textbox.focus() in ItemClick to the desired textbox. 在ItemClick中将textbox.focus()移至所需的文本框。 And given that you will not have access to the parent form in this class, I recommend you make an OnClose event in the AutoCompleteListView and subscribe to it in the parent form, to set the focus to somewhere. 考虑到您将无法访问此类中的父窗体,我建议您在AutoCompleteListView中创建一个OnClose事件并在父窗体中进行订阅,以将焦点设置到某个位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM