Represents a Windows up-down control that displays string values.
Object
MarshalByRefObject
MarshalByRefComponent
Control
RichControl
ScrollableControl
ContainerControl
UpDownBase
DomainUpDown
[Visual Basic] Public Class DomainUpDown Inherits UpDownBase [C#] public class DomainUpDown : UpDownBase [C++] public __gc class DomainUpDown : public UpDownBase [JScript] public class DomainUpDown extends UpDownBase
A DomainUpDown control displays a single string value that is selected from an Object collection by clicking the up or down buttons of the control. The user can also enter text in the control, unless the ReadOnly property is set to true (the string typed in must match an item in the collection to be accepted). When an item is selected, the object is converted to a string value so it may be displayed in the up-down control.
To create a collection of objects to display in the DomainUpDown control, you can add the items individually by using the System.WinForms.DomainUpDownItems.Add method. This may be called in an event handler such as the System.WinForms.Control.Click of a button. Alternatively, you can set the Items System.WinForms.DomainUpDownItems.All property equal to an array of objects. The object collection may be sorted alphabetically by setting the Sorted property to true. When Wrap is set to true, if you scroll past the last or first object in the collection, the list will start over with the first or last object respectively, and appear to roll in a continuous list.
When the UpButton or DownButton methods are called, either in code or by the click of the up or down buttons, UpdateEditText is called to update the control with the new string. If UserEdit is set to true, the string is matched to one of the values in the collection prior to updating the control's text display.
Namespace: System.WinForms
Assembly: System.WinForms.dll
The following example instantiates and initializes a DomainUpDown control. The example allows you to set some of its properties and create a collection of strings for display in the up-down control. The code assumes that a Label, TextBox, CheckBox and a Button have been instantiated on a form. You can enter a string in the text box and add it to the System.WinForms.DomainUpDownItems.Items collection when the button is clicked. By clicking the check box, you can toggle the Sorted property and observe the the difference in the collection of items in the up-down control.
[Visual Basic]
' Instantiate the DomainUpDown control. Private DomainUpDown1 As System.WinForms.DomainUpDown Private myCounter as Integer Private Sub MySub() ' Initialize the DomainUpDown control. Form1.DomainUpDown1 = New System.WinForms.DomainUpDown End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) ' Add the text box contents to the DomainUpDown control and ' and its initial location in the collection. DomainUpDown1.Items.Add(Trim(TextBox1.Text) & " - " & myCounter) ' Increment the counter variable. myCounter = myCounter + 1 'Clear the TextBox. TextBox1.Text = "" End Sub Private Sub CheckBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) ' If Sorted is set to true, set it to false; otherwise set it to true. If DomainUpDown1.Sorted = True Then DomainUpDown1.Sorted = False Else DomainUpDown1.Sorted = True End If End Sub Private Sub DomainUpDown1_SelectedItemChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) ' Display the SelectedIndex & SelectedItem property values in the label. Label1.Text = "SelectedIndex: " & DomainUpDown1.SelectedIndex & vbcrlf & _ "SelectedItem: " & DomainUpDown1.SelectedItem End Sub
DomainUpDown Members | System.WinForms Namespace | UpDownBase | System.WinForms.DomainUpDown.NumericUpDown