【问题标题】:Autocomplete - Append and getting only the text the user has inputed on combobox自动完成 - 附加并仅获取用户在组合框中输入的文本
【发布时间】:2017-11-09 21:33:41
【问题描述】:

我有一个ComboBox,我是这样设置的:

this.cmbCustomerJob.DisplayMember = "display";
this.cmbCustomerJob.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
this.cmbCustomerJob.AutoCompleteSource = AutoCompleteSource.ListItems;
this.cmbCustomerJob.DropDownStyle = ComboBoxStyle.DropDown;

但是我弄乱了KeyPressed 事件以防止用户在ComboBox 中输入新术语,但是当我执行cmbCustomerJob.Text 时,它甚至会返回建议的部分,我怎样才能只获得用户输入了吗?

【问题讨论】:

    标签: c# winforms autocomplete


    【解决方案1】:

    我找到了答案,我这样做了:

    strNew = ((ComboBox)sender).Text.Substring(0, ((ComboBox)sender).SelectionStart) + c.ToString();
    

    它从一开始就抓取Text (0) 到选择开始时 (SelectionStart),c.ToString()KeyPressEventArgs.KeyChar

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-04
      • 1970-01-01
      • 2012-08-08
      • 1970-01-01
      • 2012-03-14
      • 1970-01-01
      相关资源
      最近更新 更多