C# windows forms drop down menu


















The following method is initiated at application startup and in response to a user request to add a new language to the Language menu item that appears in the File menu on my menustrip and was created at design time.

Initially the Language item has no dropdown items associated with it. The languages, along with other user options, are persisted via an XML file created within the application.

The XML file is being updated correctly. GetLanguages at the start delivers the current languages in the XML file which are sorted into alphabetic order. I initially clear any existing dropdown items in order to add the updated current set in the correct order.

The main foreach loop enumerates these languages creating a ToolStripMenuItem containing the name and an optional shortcut key, all of which works fine. I originally did not use a List to AddRange these, instead just added them one after the other see the commented out line near the end.

The final foreach loop is for testing purposes only and indicates that all the languages have been set in the mnuLanguages. My problem is that whenever I access the File Language menu, the only item that appears is the alphabetically last - i. This item responds correctly to being clicked or to the shortcut key being entered.

But where are the rest??? Note that you can add any type of item to the ComboBox. If you don't specify the DisplayMember and ValueMember properties, the ComboBox uses the ToString method of the object to determine the text displayed and you can retrieve the selected item not selected value through the SelectedItem property. You need to set a datasource for your Combobox, it's better if you create a class and pass a list of Objects, for example:.

It seems like the value is just a reference to what item is selected, correct? Then you can use the index of the combobox, makes it a lot easier. Not sure if your items are known before build, if yes, then just add them in the designer, properties of the combobox.

If not, then you can add them dynamically by just doing:. ComboBox displays the result returns from the ToString call, so you can define a Display class that wraps value and display text and add those to your combobox. For creating a dropdown in controller use the selectlistitem in get method.

And same you need to paas in post method too. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Asked 7 years ago. Active 1 year, 2 months ago.

The default is null. The assigned object is not a ContextMenu. The following code example creates a ToolBar and three ToolBarButton controls, assigns the buttons to the toolbar, and sets some of the buttons' common properties. You can specify a ContextMenu to be displayed when the drop-down button is clicked. Although the DropDownMenu property is defined as a Menu type, you must assign it a ContextMenu for it to display properly. Raises the Opened event. Raises the Opening event. Raises the PaddingChanged event.

Raises the Paint event. Raises the Paint event for the ToolStrip background. Raises the PaintGrip event. Raises the BackColorChanged event when the BackColor property value of the control's container changes. Raises the BackgroundImageChanged event when the BackgroundImage property value of the control's container changes. Raises the BindingContextChanged event when the BindingContext property value of the control's container changes. Raises the ParentChanged event. Raises the EnabledChanged event when the Enabled property value of the control's container changes.

Raises the FontChanged event when the Font property value of the control's container changes. Raises the ForeColorChanged event when the ForeColor property value of the control's container changes. Raises the VisibleChanged event when the Visible property value of the control's container changes. Raises the PreviewKeyDown event. Raises the QueryContinueDrag event. Raises the RegionChanged event. Raises the RendererChanged event. Raises the Resize event.

Raises the RightToLeftChanged event. Raises the Scroll event. Raises the SizeChanged event. Raises the StyleChanged event. Raises the SystemColorsChanged event. Raises the TabIndexChanged event. Raises the TabStopChanged event. Raises the TextChanged event. Raises the Validated event. Raises the Validating event. Raises the VisibleChanged event. Forces the control to invalidate its client area and immediately redraw itself and any child controls. When overridden in a derived class, handles the rescaling of any magic numbers that are used in control painting.

Resets the BackColor property to its default value. Causes a control bound to the BindingSource to reread all the items in the list and refresh their displayed values. Resets the Cursor property to its default value.

Resets the Font property to its default value. Resets the ForeColor property to its default value. Resets the ImeMode property to its default value. Resets the control to handle the MouseLeave event. Resets the RightToLeft property to its default value. Resets the Text property to its default value Empty. Converts the specified ContentAlignment to the appropriate ContentAlignment to support right-to-left text.

Converts the specified HorizontalAlignment to the appropriate HorizontalAlignment to support right-to-left text.

Activates a child control. Optionally specifies the direction in the tab order to select the control from. Sets a value indicating how a control will behave when its AutoSize property is enabled. Sets a specified ControlStyles flag to either true or false. Displays the ToolStripDropDown control in its default position. Positions the ToolStripDropDown relative to the specified control's horizontal and vertical screen coordinates.

Positions the ToolStripDropDown relative to the specified control location. Positions the ToolStripDropDown relative to the specified control at the specified location and with the specified direction relative to the parent control.

Positions the ToolStripDropDown relative to the specified screen coordinates. Positions the ToolStripDropDown relative to the specified screen location. Positions the ToolStripDropDown relative to the specified control location and with the specified direction relative to the parent control. Returns a string that represents the ToolStrip control. Occurs when the AutoSize property has changed. Occurs when the value of the BackColor property changes. Occurs when the value of the BackgroundImage property changes.

Occurs when the user begins to drag the ToolStrip control. Occurs when the value of the BindingContext property changes. Occurs when the CausesValidation property changes. Occurs when the value of the ClientSize property changes. Occurs when the ToolStripDropDown is closed. Occurs when the ToolStripDropDown control is about to close. Occurs when the value of the ContextMenu property changes.

Occurs when the value of the Cursor property changes. Occurs when the component is disposed by a call to the Dispose method. Occurs when the DPI setting for a control is changed programmatically after the DPI of its parent control or form has changed. Occurs when the DPI setting for a control is changed programmatically before a DPI change event for its parent control or form has occurred. Occurs when the Enabled property value has changed. Occurs when the user stops dragging the ToolStrip control.

Occurs when the focus enters the ToolStripDropDown. Occurs when the value of the Font property changes. Occurs when the value of the ForeColor property changes. Occurs when the ImeModeChanged property has changed. Occurs when the ToolStripItem is clicked. Occurs when a key is pressed and held down while the ToolStripDropDown has focus.

Occurs when a key is pressed while the ToolStripDropDown has focus. Occurs when the layout of the ToolStrip is complete. Occurs when the value of the LayoutStyle property changes. Occurs when the Location property value has changed. Occurs when the ToolStripDropDown is opened.

Occurs when the ToolStripDropDown control is opening. Occurs when the ToolStrip move handle is painted. Occurs when the Parent property value changes. Occurs before the KeyDown event when a key is pressed while focus is on this control.

Occurs when AccessibleObject is providing help to accessibility applications. Occurs during a drag-and-drop operation and enables the drag source to determine whether the drag-and-drop operation should be canceled. Occurs when the value of the Region property changes. Occurs when the value of the Renderer property changes. Occurs when the RightToLeft property value changes. Occurs when the Size property value changes. Occurs when the ToolStripLayoutStyle style changes. Occurs when the Visible property value changes.

Skip to main content. This browser is no longer supported. Download Microsoft Edge More info. Contents Exit focus mode. Please rate your experience Yes No. Any additional feedback? Namespace: System. Forms Assembly: System. In this article. Inherited from ScrollableControl. Determines whether the user has enabled full window drag. Inherited from Control. Gets or sets the description of the control used by accessibility client applications.

Gets or sets the name of the control used by accessibility client applications. Gets or sets the accessible role of the control. Inherited from ToolStrip. This property is not relevant for this class. Gets or sets the background image displayed in the control. Gets a value indicating whether the control can receive focus. Determines if events can be raised on the control. Gets a value indicating whether the control can be selected. Gets or sets a value indicating whether the control has captured the mouse.

Gets the rectangle that represents the client area of the control. Gets or sets the height and width of the client area of the control. Gets the name of the company or creator of the application containing the control.

Inherited from Component. Gets or sets the shortcut menu associated with the control. Gets a value indicating whether the control has been created. Gets the data bindings for the control. Gets or sets the default cursor for the control. Gets the DPI value for the display device where the control is currently being displayed. Retrieves the current display rectangle.

Gets the dock padding settings for all edges of the control. Gets or sets a value indicating whether the control can respond to user interaction. Gets a value indicating whether the control has input focus. Gets or sets the height of the font of the control. Gets the window handle that the control is bound to.

Gets or sets the height of the control. Gets or sets a value indicating whether the horizontal scroll bar is visible. Gets or sets the IME mode of a control.



0コメント

  • 1000 / 1000