vb.net 在 Vb 中选择项目时如何去除组合框的突出显示?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38813356/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to remove highlight of combobox when an Item is selected in Vb?
提问by Rahman Jalayer
In load page event:
在加载页面事件中:
I read some data from DB and then add this data to Combo box then select an item as default and enable of combo box changes to false. When I load this page, the item witch selected highlights with blue color.
我从数据库中读取了一些数据,然后将此数据添加到组合框,然后选择一个项目作为默认值,并将组合框的启用更改为 false。当我加载此页面时,女巫选择的项目以蓝色突出显示。
How to remove this highlight?
如何去除这个亮点?
采纳答案by Visual Vincent
You can modify its SelectionLengthproperty, which gets or sets how many characters have been selected (highlighted).
您可以修改其SelectionLength属性,该属性获取或设置已选择(突出显示)的字符数。
Just set it to 0after you have selected the default item and you should be good to go:
只需0在选择默认项目后将其设置为,就可以了:
ComboBox1.SelectionLength = 0
EDIT:
编辑:
In your case this code is executed before the Loadevent has finished. Due to this the form has not been rendered yet, which is why it is not working for you.
在您的情况下,此代码在Load事件完成之前执行。因此,表单尚未呈现,这就是它不适合您的原因。
The simple fix is to add this in the form's Shownevent too:
简单的解决方法是在表单的Shown事件中也添加这个:
Private Sub Form1_Shown(sender As Object, e As System.EventArgs) Handles Me.Shown
ComboBox1.SelectionLength = 0
End Sub
If you don't want the caret to be in the beginning you can also add this line to set it to the end of the text:
如果您不希望插入符号位于开头,您还可以添加此行以将其设置为文本的末尾:
ComboBox1.SelectionStart = ComboBox1.Text.Length
回答by Zibri
The proposed solution does not work in VB.NET 2016 The easiest way to do is to pass focus to another element like a label in the SelectedIndexChanged event
建议的解决方案在 VB.NET 2016 中不起作用最简单的方法是将焦点传递给另一个元素,如 SelectedIndexChanged 事件中的标签

