0

I'm converting an old VB form to .NET, and there a few Buttons which each have a corresponding ComboBox hiding behind them. The previous behavior was that you'd click the Button, and that would trigger the ComboBox behind it, which would then drop down a selection list. I believe the idea was to have a static color and text label (which cannot be a selectable option in the drop-down list), with the functionality of a ComboBox.

Now, in VB.NET, clicking on the Button (which is directly over the ComboBox in the form) won't trigger the ComboBox dropdown anymore. However, if I make the ComboBox visible enough to click on, it will trigger the ComboBox.TextChanged event, and show the drop-down (they're set to the DropDownList style). I've set the event handler to handle both that event and the Button event. I've tried Button.MouseDown, Button.MouseClick, and Button.Click -- none of which have worked.

I did find the SplitButton control option suggested here, which would probably do the job, but I don't want to have to integrate a non-native control for just 3 buttons. I don't really want to mess with the control template, either -- and I'm not sure that would be a solution, anyway.

Why is the ComboBox not triggering?

Community
  • 1
  • 1
Wingman4l7
  • 649
  • 1
  • 8
  • 23

1 Answers1

1

I am not sure exactly what you are trying to visualy do. But you can set the ComboBox.DroppedDown Property to True in your Button Click Event to trigger the DropDown. Which should look like this.

enter image description here

Mark Hall
  • 53,938
  • 9
  • 94
  • 111
  • Basically, I'm trying to have a ComboBox with a static appearance. This was previously "faked" by hiding the ComboBox behind a button, and triggering the drop-down when the button was clicked. – Wingman4l7 Jun 26 '12 at 01:20
  • @Wingman4l7 I just added an Image is that what you are wanting? – Mark Hall Jun 26 '12 at 01:22
  • Yes, that's what I'm looking for; that solution sounds like it should work, but I'm testing it and it doesn't seem to. I'm still curious as to why a control "behind" another control wouldn't trigger when a click occurs within its location. – Wingman4l7 Jun 26 '12 at 01:28
  • @Wingman4l7 The Button handles the Click Event and the ComboBox never sees it. I just put ComboBox1.DroppedDown = True in the Button click event and it worked. What you are wanting is more like routed events in WPF – Mark Hall Jun 26 '12 at 01:35
  • 1
    @Wingman4l7 To further explain what is going on look at this [CodeProject Article](http://www.codeproject.com/Articles/13216/Broadcasting-Events-through-a-Control-Hierarchy) – Mark Hall Jun 26 '12 at 01:43
  • It looks like the ComboBox will display the drop-down upon clicking, regardless of whether or not it has an event handler for it; interesting. This solution does what I need; thanks! – Wingman4l7 Jun 26 '12 at 01:58