我有一个ComboBox
,我设置如下:
this.cmbCustomerJob.DisplayMember = "display";
this.cmbCustomerJob.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
this.cmbCustomerJob.AutoCompleteSource = AutoCompleteSource.ListItems;
this.cmbCustomerJob.DropDownStyle = ComboBoxStyle.DropDown;
但是,我正在弄乱KeyPressed
事件以阻止用户在ComboBox
中输入新字词,但是当我执行cmbCustomerJob.Text
时,它甚至会返回建议的部分,我只能获得用户键入的内容吗?
答案 0 :(得分:1)
我找到了答案,我这样做了:
strNew = ((ComboBox)sender).Text.Substring(0, ((ComboBox)sender).SelectionStart) + c.ToString();
从开始(Text
)抓取0
到选择开始(SelectionStart
),c.ToString()
是KeyPressEventArgs.KeyChar