簡體   English   中英

c#組合框自動完成建議添加問題

[英]c# combobox autocomplete suggestappend issues

在我的WinForm-Application中,我有一些帶有AutoCompleteMode作為SuggestAppendAutoCompleteSource.ListItems組合框。

如果組合框為空,並且我鍵入“ f”,則會彈出列表,其中包含條目“ foo”。 文本將自動附加到foo。 如果我通過單擊制表符跳到下一個控件,則組合框將選擇條目foo。 精細。

如果組合框已經選擇了條目“ foo”,並且我鍵入“ f”,則會彈出列表,其中包含條目“ foo”,但是文本不會自動附加到foo。 如果我通過單擊Tab跳到下一個控件,則組合框不會選擇條目foo,所顯示的文本將保持為'f'。 我希望它具有與上述相同的行為。

像這樣使用combobox的Leave事件,

private void comboBox1_Leave(object sender, EventArgs e)
{
     string item = source.FirstOrDefault(x => x.StartsWith(comboBox1.Text));  
     //search string inside source of suggests and if there is a match get the first one
     if(!string.IsNullOrEmpty(item)) 
     {
          int index = comboBox1.Items.IndexOf(item); // find it inside combobox items
          comboBox1.SelectedIndex = index; // and select it

      }
}

希望有幫助,

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM