Click here to Skip to main content
15,888,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I currently have a dropdown box called, "dropdownDeviceSelector" with the current fields in the Main.Designer.cs class:
this.dropdownDeviceSelector.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)| System.Windows.Forms.AnchorStyles.Right))); 
this.dropdownDeviceSelector.FormattingEnabled = true;
this.dropdownDeviceSelector.Location = new System.Drawing.Point(407, 100);
this.dropdownDeviceSelector.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.dropdownDeviceSelector.Name = "dropdownDeviceSelector";
this.dropdownDeviceSelector.Size = new System.Drawing.Size(100, 28);
this.dropdownDeviceSelector.TabIndex = 4;


And then, I have a function in my Main.cs file called, "chooseDevice":
private void chooseDevice(object sender, EventArgs e)
        {
            // display the dropdown menu when this function is called
        }


However, I only want the dropdownDeviceSelector to appear when the function chooseDevice is called. I'm very new to winforms so I don't really know how to implement this.

What I have tried:

I have tried calling the dropdown box in the function to no avail. I'm very new to winforms so I'm not really sure how this is done.
Posted
Updated 9-Dec-20 3:51am
Comments
CHill60 9-Dec-20 9:46am    
What is the actual control - is it a ComboBox?
stevenlam505 9-Dec-20 9:47am    
Yes it is using ComboBox
CHill60 9-Dec-20 9:51am    
Is there a .Visible property - if you type this.dropdownDeviceSelector then a full stop you should get a list of properties and methods. Look for Visible - if it is there then just set it to False to make the control disappear and True to bring it back
stevenlam505 9-Dec-20 9:58am    
Ah, this worked, thank you!

1 solution

You could make the dropdown box non-visible so it only shows when you call your function. But it does rather depend on what exactly you are trying to achieve. What is contained in the device list, and how does the user cause the chooseDevice function to be called? In most cases you would have the list showing, and have some action button which is disabled, but gets enabled when the user makes a selection from the dropdown.
 
Share this answer
 
Comments
stevenlam505 9-Dec-20 9:55am    
The device list will only contain two choices, and when they select a choice, I want that choice to be stored inside of a variable named deviceChoice. In most cases, I want the list to be not visible unless the user chooses an option in another menu. IE, if the user chooses to "Choose Device" instead of "Modify Device", it displays the dropdown menu.
Richard MacCutchan 9-Dec-20 10:27am    
OK, so once the user selects "Choose Device" you can show the dropdown. You can either do it by changing the Visible property, or creating the dropdown dynamically at run time. The second option may be the better choice, assuming this is the only time you require the dropdown. It does seem something of overkill to use a dropdown list when there are only two choices. You could get just the same effect with a pair of radio buttons.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900