2013-12-18 167 views
3

我有一個ComboBoxDropDownStyle = Simple並將其綁定到DataSet。我想要的是:當我輸入'a'時,我希望我的ComboBox只顯示以字母'a'開頭的項目,即字典程序。Vb.net ComboBox自動完成

我有嘗試AutoComplete屬性,但它只是顯示DropDown,它不是我想要的

感謝和抱歉,如果我做我的問題不明確或可理解的,因爲我在這裏首發。

這裏是我的代碼:

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 

回答

2

更改此設置

DropDownStyle = DropDownList 
7

您需要設置這些屬性自動完成

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 
2
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 
0

的答案很簡單。像通常一樣通過添加顯示成員和值成員來加載組合框。然後,您通過顯示成員和whala加載自動填充。請記住,在正常情況下,自動完成功能基本上只是顯示部件一側的過濾選項。

下面是一個例子。請記住,此示例從我們的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