.NET Is it possible to have a contextmenu on an item of a combobox?

后端 未结 6 1638
迷失自我
迷失自我 2021-01-20 04:42

In my application I have dropdown list with several items. I\'d like to show a context menu when the user clicks the right mouse button on a dropdown item. Is this possible?

6条回答
  •  轮回少年
    2021-01-20 05:10

    It is possible but not easy. The ComboBox dropdown is a native ListBox that is created on-the-fly. To get the handle of that list box, you have to send the CB_GETCOMBOBOXINFO message in the DropDown event. Check my answer in this thread to find out how to do this.

    The iceberg that is likely to sink that Titanic is that the dropdown automatically closes as soon as it loses focus. Which will happen as soon as you display the context menu. Nothing you can do about that.

    Consider a different approach, you could use an actual ListBox that you make visible when the user clicks a glyph that looks like an arrow next a TextBox.

提交回复
热议问题