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

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

问题描述

所以我在读在VB.NET文本框自动完成了一点,但我真的不能明白的地方,这些被存储?它是一个完全内置的功能,还是我必须写一些code为它工作?我发现文本框的 AutoCompleteMode AutoCompleteSource 属性。但我想任何附加我写在文本框中自动完成源。难道我的源连接到 My.Settings 还是什么?难道不是我要使用一个数组中呢?任何帮助将是AP preciated:)

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?

您可以添加如新价值当输入字段的验证情况,或者当用户presses一个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 来几乎所有的东西;这是非常相似的数据绑定。有一点要记住的是,如果你要添加新条目自动完成数据源,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天全站免登陆