自动填充 - 仅添加和获取用户在组合框中输入的文本

时间:2008-12-11 17:49:43

标签: c# winforms autocomplete

我有一个ComboBox,我设置如下:

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

但是,我正在弄乱KeyPressed事件以阻止用户在ComboBox中输入新字词,但是当我执行cmbCustomerJob.Text时,它甚至会返回建议的部分,我只能获得用户键入的内容吗?

1 个答案:

答案 0 :(得分:1)

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

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

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

豫ICP备18024241号-1