【问题标题】:C# combobox dropdownC# 组合框下拉菜单
【发布时间】:2017-04-25 13:06:17
【问题描述】:

我希望我的组合框在我按下文本字段和下拉符号时下拉

我已经这样做了:

private void comboBoxOpretKomponentLevel_Enter(object sender, EventArgs e)
{           
    if (comboBoxOpretKomponentLevel.SelectedIndex <= 0)
    {
        comboBoxOpretKomponentLevel.Text = null;
    }
    comboBoxOpretKomponentLevel.Focus();       
    comboBoxOpretKomponentLevel.DroppedDown = true;           
}

.Droppeddown = true 使其在选择文本时起作用(“选择产品”) 但是当按下 dropbox 的下拉符号时 - dropdown 再次变为 false。 我该如何进行这项工作? 据我所知,我不能使用 DropDownList,因为我不能拥有我的(“选择产品”)文本。

【问题讨论】:

  • 当我再次按下它时它会变假?你的意思是它关闭...?因为这不是预期的行为
  • 好吧,也许我解释得不够好!当我按下下拉符号时 - 下拉菜单打开 - 但是当它进入 _Enter 事件时,它会在执行 .Dropdown = true 命令时再次关闭下拉菜单。所以结果是它快速打开下拉列表,然后再次关闭。

标签: c# winforms


【解决方案1】:

我会简单地使用MouseClickevent。由于您的问题太宽泛,我只有这段代码可以帮助您。

它的作用是,只有当您 click ComboBox 或任何与 ComboBox 有关的控制器时,它才会打开 dropdownlist。要在 Form_Load 事件上简单地关闭它 click ,它将空闲 dropdownlist

private void comboBoxOpretKomponentLevel_MouseClick(object sender, MouseEventArgs e)
    {
        //This piece will dropdown the combobox once you click it.
        comboBoxOpretKomponentLevel.DroppedDown = true;
        comboBoxOpretKomponentLevel.Focus();  
    }
private void YourForm_Click (object sender, EventArgs e)
    {
        //This piece will simply close the dropdown from your combobox and  use the selected value.
        comboBoxOpretKomponentLevel.DroppedDown = false;

    }

希望对您有所帮助,否则只需重新提出您的问题,以便我们为您提供帮助。

【讨论】:

    猜你喜欢
    • 2018-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多