Vb.net + 文本框中的自动完成 [英] Vb.net + AutoComplete in textboxes

查看:28
本文介绍了Vb.net + 文本框中的自动完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我读了一些关于 VB.NET 中文本框的 AutoComplete 的内容,但我真的不明白这些文本框的存储位置?它是一个完全内置的功能,还是我必须编写一些代码才能让它工作?我找到了文本框的 AutoCompleteModeAutoCompleteSource 属性.但我想将我在文本框中写的任何内容附加到自动完成源中.我是否将源连接到 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 + 文本框中的自动完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆