DomainUpDown Class
Represents a Windows spin box (also known as an up-down control) that displays string values.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
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 can be displayed in the spin box.
To create a collection of objects to display in the DomainUpDown control, you can add or remove the items individually by using the Add and Remove methods. This can be called in an event handler, such as the Click event of a button. The object collection can be sorted alphabetically by setting the Sorted property to true. When the Wrap property 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.
The following code example creates 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 spin box. The code assumes that a TextBox, CheckBox, and Button have been instantiated on a form. The example also assumes that you have a member variable at the class level declared as a 32-bit signed integer named myCounter. You can enter a string in the text box and add it to the Items collection when the button is clicked. By clicking the check box, you can toggle the Sorted property and observe the difference in the collection of items in the spin box.
Protected domainUpDown1 As DomainUpDown Private Sub MySub() ' Create and initialize the DomainUpDown control. domainUpDown1 = New System.Windows.Forms.DomainUpDown() ' Add the DomainUpDown control to the form. Controls.Add(domainUpDown1) End Sub 'MySub Private Sub button1_Click(sender As System.Object, e As System.EventArgs) ' Add the text box contents and initial location in the collection ' to the DomainUpDown control. domainUpDown1.Items.Add((textBox1.Text.Trim() & " - " & myCounter)) ' Increment the counter variable. myCounter = myCounter + 1 ' Clear the TextBox. textBox1.Text = "" End Sub 'button1_Click Private Sub checkBox1_Click(sender As System.Object, e As System.EventArgs) ' If Sorted is set to true, set it to false; ' otherwise set it to true. If domainUpDown1.Sorted Then domainUpDown1.Sorted = False Else domainUpDown1.Sorted = True End If End Sub 'checkBox1_Click Private Sub domainUpDown1_SelectedItemChanged _ (sender As System.Object, e As System.EventArgs) ' Display the SelectedIndex and SelectedItem property values in a MessageBox. MessageBox.Show(("SelectedIndex: " & domainUpDown1.SelectedIndex.ToString() & _ ControlChars.Cr & "SelectedItem: " & domainUpDown1.SelectedItem.ToString())) End Sub 'domainUpDown1_SelectedItemChanged
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Pocket PC
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.