Combobox和自动填充在C# [英] Combobox and autocomplete in C#

查看:298
本文介绍了Combobox和自动填充在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在组合框中的自动完成选项有小问题。一切正常,除非我想工作它不同:)



当我开始在combobox中打字时,autusuggest工作我喜欢的方式:









更多我不能从autosuggest组合框中选择项目,只能从此列表下。



自动完成模式是SuggestAppend



我想要像第一张图片一样自动建议,在图片2第一个组合框列表应该以某种方式关闭。

解决方案

我有同样的问题, b
$ b

  private void comboBox_DropDown(object sender,EventArgs e)
{
ComboBox cbo =
cbo.PreviewKeyDown + = new PreviewKeyDownEventHandler(comboBox_PreviewKeyDown);
}

private void comboBox_PreviewKeyDown(object sender,PreviewKeyDownEventArgs e)
{
ComboBox cbo =(ComboBox)sender;
cbo.PreviewKeyDown - = comboBox_PreviewKeyDown;
if(cbo.DroppedDown)cbo.Focus();
}

用户点击 DropDown 按钮 PreviewKeyDown 事件附加到 ComboBox 。当用户开始键入时,触发新添加的事件。在这种情况下,我们检查 ComboBox DroppedDown ,如果是,集中 ComboBox ComboBox 焦点 DropDown 消失,就是这样。


i have small problem with autocomplete option in combobox. Everything is working correct, except that i want to work it diffrent :)

When I start typing in combobox, autusuggest working the way i like :

But when i first open combobox, and then start typing i get something like that:

What's more i can't pick item from autosuggest combobox, only from this list under.

AutocompleteMode is SuggestAppend

I'd like to have autosuggest like on the first picture, and in situations like picture 2, this first combobox list should be closed somehow..

解决方案

I had the same problem and solved it this way:

private void comboBox_DropDown(object sender, EventArgs e)
{
    ComboBox cbo = (ComboBox)sender;
    cbo.PreviewKeyDown += new PreviewKeyDownEventHandler(comboBox_PreviewKeyDown);
}

private void comboBox_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
    ComboBox cbo = (ComboBox)sender;
    cbo.PreviewKeyDown -= comboBox_PreviewKeyDown;
    if (cbo.DroppedDown) cbo.Focus();
}

Once the user clicks on the DropDown button PreviewKeyDown event is attached to that ComboBox. When user starts typing, freshly added event is triggered. In that event we check if ComboBox is DroppedDown, if it is, focus that ComboBox. On ComboBox focus DropDown disappeares and that's it.

这篇关于Combobox和自动填充在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆