C# equivalent for ShowDropDown?
-
Hi, I'm trying to prevent a combo box from displaying the dropdown when the user clicks on it. MFC's ShowDropDown(false) was doing this. Is there a way to accomplish the same result in C#? thanx
-
Hello, You just have to set the Boolean property "DroppedDown" to "true". All the best, Martin
-
Martin, I tried that, but the dropdown flickers. It comes up and it dissapears right away. Is there a way to prevent it from appearing? thanx
-
I'm doing it on DropDown event: this.comboBox1.DropDown += new System.EventHandler(this.comboBox1_DropDown_1); ........... private void comboBox1_DropDown_1(object sender, System.EventArgs e) { this.comboBox1.DroppedDown = true; } It's pretty weird. The first click won't show it, but the second click will.
-
I'm doing it on DropDown event: this.comboBox1.DropDown += new System.EventHandler(this.comboBox1_DropDown_1); ........... private void comboBox1_DropDown_1(object sender, System.EventArgs e) { this.comboBox1.DroppedDown = true; } It's pretty weird. The first click won't show it, but the second click will.
-
Hmmm, I don't understand why you are doing that! You said that you whant it to show when the user clicks the control. So I would rather use the click or mousedown event of the combobox. Hope it helps! All the best, Martin
-
No Martin, I want to prevent the combo from showing the dropdown (the reason is that i'm doing something else instead of showing the list). I think I'll just fake it with an edit & a button.
Ohh, Than I missunderstod what you actually wanted to do. I made a little test project for you, which is doing: The dropdown box should be shown if the left mouse button is clicked, but not if the right mouse button is clicked. I'm using the mousedown event for that.
private System.Windows.Forms.ContextMenu emptymenu = new ContextMenu(); private System.Windows.Forms.ContextMenu oldmenu; private void button1\_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { if(e.Button == MouseButtons.Right) { if(button1.ContextMenu!=emptymenu) oldmenu = button1.ContextMenu; //this will save the original menu. button1.ContextMenu = emptymenu; //this setts a empty menu to the property, which has the effect that no menu is shown. } else if(e.Button == MouseButtons.Left) { if(oldmenu!=null) //the right mouse button was already pressed { button1.ContextMenu = oldmenu; } button1.ContextMenu.Show(button1, new Point(e.X,e.Y)); } }
Hope it helps! All the best, Martin