Editbox portion of ComboBox gets selected automatically

后端 未结 7 1266
隐瞒了意图╮
隐瞒了意图╮ 2020-12-30 02:49

I have a small problem that has been annoying me for some hours.

In my WinForms (.NET 3.5) application I create some ComboBoxes (DropDownStyle = DropDown) in a Table

7条回答
  •  遥遥无期
    2020-12-30 03:27

    This is an old question, but I found it searching for an answer and ended up implementing my own solution. Might as well post it here, right?

        foreach (var cb in Controls.OfType())
        {
            cb.Resize += (sender, e) => {
                if (!cb.Focused)
                    cb.SelectionLength = 0;
            };
        }
    

    intentionally selected text became deselected

    This WinForms bug doesn't affect selected ComboBoxes, so by ignoring the ones with Focus, we take care of the problem of losing current selections.

    I would have to add the event handler to each and every ComboBox on my dialog.

    Taken care of by the foreach loop. Put it in InitializeComponent() or your .ctor if you don't want to break the designer, or have the designer break this.

    there was a lot of flicker

    I'm only seeing flicker if I resize very fast, but I'm on Win7 so it might be different on XP.

提交回复
热议问题