【问题标题】:c# combobox autocomplete suggestappend issues时间:2019-05-10 标签:c#combobox autocompleteSuggestappend问题
【发布时间】:2017-05-19 22:17:58
【问题描述】:

在我的 WinForm 应用程序中,我有一些组合框,AutoCompleteModeSuggestAppendAutoCompleteSource.ListItems

如果组合框为空并且我键入“f”,则列表会弹出,其中包含条目“foo”。文本自动附加到 foo。如果我通过点击选项卡跳转到下一个控件,组合框会选择条目 foo。很好。

如果组合框已经选择了条目“foo”并且我输入了“f”,则列表会弹出,其中包含条目“foo”,但文本不会自动附加到 foo。如果我通过点击选项卡跳转到下一个控件,组合框不会选择条目 foo,正在显示的文本保持为“f”。我希望它具有与上述相同的行为。

【问题讨论】:

    标签: c# winforms combobox autocomplete


    【解决方案1】:

    像这样使用组合框的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
    
          }
    }
    

    希望有帮助,

    【讨论】:

      猜你喜欢
      • 2020-06-15
      • 2020-10-01
      • 2015-06-14
      • 2011-07-08
      • 2012-02-03
      • 2017-04-15
      • 2021-07-31
      • 2016-01-27
      • 1970-01-01
      相关资源
      最近更新 更多