Vb.net + 文本框中的自动完成

编程入门 行业动态 更新时间:2024-10-24 06:39:12
本文介绍了Vb + 文本框中的自动完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

所以我读了一些关于 VB.NET 中文本框的 AutoComplete 的内容,但我真的不明白这些文本框的存储位置?它是一个完全内置的功能,还是我必须编写一些代码才能让它工作?我找到了文本框的 AutoCompleteMode 和 AutoCompleteSource 属性.但我想将我在文本框中写的任何内容附加到自动完成源中.我是否将源连接到 My.Settings 或其他东西?难道我也不必使用数组吗?任何帮助将不胜感激:)

So I was reading a bit on AutoComplete of textboxes in VB.NET, but I can't really understand where these are stored? Is it a fully built in feature, or do I have to write some code for it to work? I've found the AutoCompleteMode and AutoCompleteSource properties of textboxes. But I want to append whatever I've written in the textbox to the autocomplete source. Do I connect the source to My.Settings or something? Wouldn't I have to use an array as well? Any help would be appreciated :)

推荐答案

您必须手动将新条目添加到您的自动完成数据源中......这很有意义,当您考虑它时:Windows 窗体应该如何想知道什么时候应该将新条目添加到建议列表中,什么时候输入的文本只是暂时的?

You would have to add new entries to your auto-complete data source manually... which makes sense, when you think about it: How is Windows Forms supposed to know when a new entry should be added to the list of suggestions and when the text entered is only something temporary?

您可以添加新值,例如当输入字段的验证发生时,或者当用户按下 OK/Apply 按钮时,或者最适合您需要的任何时候.但是你必须自己做.

You could add new values e.g. when validation of the input field happens, or when the user presses an OK / Apply button, or whatever fits your need best. But you will have to do this yourself.

您已经发现的属性是正确的.

The properties you've already discovered are the right ones.

Dim suggestions As New List(Of String) suggestions.Add("Abba") suggestions.Add("Nirvana") suggestions.Add("Rolling Stones") ... textBox.AutoCompleteSource = suggestions

您可以将 AutoCompleteSource 绑定到几乎任何东西;这与数据绑定非常相似.要记住的一件事是,如果您向自动完成数据源添加新条目,如果您的数据源没有实现 INotifyCollectionChanged 接口,UI 控件可能不会立即注意到.

You can bind AutoCompleteSource to almost anything; this is very similar to data-binding. One thing to keep in mind is that if you're adding new entries to the auto-complete data source, the UI control might not immediately notice if your data source doesn't implement the INotifyCollectionChanged interface.

更多推荐

Vb.net + 文本框中的自动完成

本文发布于:2023-11-03 20:34:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1556021.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:框中   自动完成   文本   Vb   net

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!