Vb.net 组合框自动完成
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20649164/
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
Vb.net ComboBox Autocomplete
提问by Hia Yongkuy
I have a ComboBox
with DropDownStyle = Simple
and have bound it to a DataSet
. What I want is : when I type 'a', I want my ComboBox
to show only the items starting with the letter 'a' just Dictionary Program.
我有一个ComboBox
withDropDownStyle = Simple
并将它绑定到一个DataSet
. 我想要的是:当我输入“a”时,我希望ComboBox
只显示以字母“a”开头的项目,只是字典程序。
I have tried the AutoComplete
property but it just shows a DropDown
and that's not what I want
我已经尝试过该AutoComplete
属性,但它只显示了一个DropDown
,这不是我想要的
HERE IS MY CODE:
这是我的代码:
Private Sub TICKETING_FORM_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
da.Fill(ds, "STYLE")
bs.DataSource = ds.Tables("STYLE")
With Style_ComboBox
.DataSource = bs
.DisplayMember = "STYLE"
.ValueMember = "STYLE"
.AutoCompleteMode = AutoCompleteMode.Suggest
.AutoCompleteSource = AutoCompleteSource.ListItems
End With
End Sub
采纳答案by Jade
Change this Setting
更改此设置
DropDownStyle = DropDownList
回答by Vignesh Kumar A
You need to set these property for AutoComplete
您需要为 AutoComplete 设置这些属性
ComboBox1.AutoCompleteMode = AutoCompleteMode.Append
ComboBox1.DropDownStyle = ComboBoxStyle.DropDown
ComboBox1.AutoCompleteSource = AutoCompleteSource.ListItems
Private Sub TICKETING_FORM_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
da.Fill(ds, "STYLE")
bs.DataSource = ds.Tables("STYLE")
With Style_ComboBox
.DataSource = bs
.DisplayMember = "STYLE"
.ValueMember = "STYLE"
.DropDownStyle = ComboBoxStyle.DropDown
.AutoCompleteMode = AutoCompleteMode.Suggest
.AutoCompleteSource = AutoCompleteSource.ListItems
End With
End Sub
回答by Dandy
Private Sub TICKETING_FORM_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
da.Fill(ds, "STYLE")
bs.DataSource = ds.Tables("STYLE")
With Style_ComboBox
.DataSource = bs
.DisplayMember = "STYLE"
.ValueMember = "STYLE"
.AutoCompleteMode = AutoCompleteMode.SuggestAppend ' This is necessary
.AutoCompleteSource = AutoCompleteSource.ListItems
End With
End Sub
回答by Tuxmezoo
The answers is quite simple. You load your combobox like you would normally by adding the display member and the value member. Then you load your autocomplete by the Display member and whala. Keep in mind that the auto complete function is basicly just a filter option on the display member side under normal conditions.
答案很简单。通过添加显示成员和值成员,您可以像平常一样加载组合框。然后你通过 Display 成员和 whala 加载你的自动完成。请记住,自动完成功能基本上只是正常情况下显示成员侧的过滤选项。
Here follows and example. Keep in mind that this example draws the list of names from our AD account and is nor shown here....
下面是例子。请记住,此示例从我们的 AD 帐户中提取姓名列表,此处也未显示....
Dim col As New AutoCompleteStringCollection
Dim i As Integer
If Not MyUsers Is Nothing Then
For i = 0 To MyUsers.Rows.Count - 1
col.Add(MyUsers.Rows(i)("displayname").ToString)
Next
Request_ManagerComboBox.AutoCompleteSource = AutoCompleteSource.CustomSource
Request_ManagerComboBox.AutoCompleteCustomSource = col
Request_ManagerComboBox.AutoCompleteMode = AutoCompleteMode.SuggestAppend
Request_ManagerComboBox.DisplayMember = MyUsers.Rows(i - 1)("displayname").ToString
Request_ManagerComboBox.ValueMember = MyUsers.Rows(i - 1)("samAccountName").ToString
End If