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

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

问题描述

所以我在 VB.NET 中阅读了一些关于自动完成文本框的内容,但我无法真正理解这些文本框的存储位置?它是完全内置的功能,还是我必须编写一些代码才能使其工作?我找到了文本框的 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?

您可以添加新值,例如当输入字段验证发生时,或者当用户按下确定"/应用"按钮时,或者最适合您的需要时.但是你必须自己做这件事.

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 绑定到任何东西;这与数据绑定非常相似.要记住的一件事是,如果您向自动完成数据源添加新条目,UI 控件可能不会立即注意到您的数据源是否实现了 INotifyCollectionChanged 接口.

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天全站免登陆