ARTICLE

DomainUpDown Control in VB.NET

Posted by Dinesh Beniwal Articles | Visual Basic 2010 October 05, 2009
The Windows Forms DomainUpDown control looks like a combination of a text box and a pair of arrows for moving up or down through a list.
Download Files:
 
Reader Level:

The Windows Forms DomainUpDown control looks like a combination of a text box and a pair of arrows for moving up or down through a list. The control displays and sets a text string from a list of choices. The user can select the string by clicking up and down buttons to move through a list, by pressing the UP and DOWN ARROW keys, or by typing a string that matches an item in the list. One possible use for this control is for selecting items from an alphabetically sorted list of names. (To sort the list, set the Sorted property to true.) The function of this control is very similar to the list box or combo box, but it takes up very little space.
 
Introduction
 
The Windows Forms DomainUpDown control looks like a combination of a text box and a pair of buttons for moving up or down through a list. The control displays and sets a text string from a list of choices. The user can select the string by clicking up and down buttons to move through a list, by pressing the UP and DOWN ARROW keys, or by typing a string that matches an item in the list. One possible use for this control is for selecting items from an alphabetically sorted list of names. (To sort the list, set the Sorted property to true.) The function of this control is very similar to the list box or combo box, but it takes up very little space.

The key properties of the control are Items, ReadOnly, and Wrap. The Items property contains the list of objects whose text values are displayed in the control. If ReadOnly is set to false, the control automatically completes text that the user types and matches it to a value in the list. If Wrap is set to true, scrolling past the last item will take you to the first item in the list and vice versa. The key methods of the control are UpButton and DownButton.

This control displays only text strings. If you want a control that displays numeric values, use the NumericUpDown control. For more information, see Introduction to the Windows Forms NumericUpDown Control.

Adding Items from DomainUpDown Controls
 
You can add items to the Windows Forms DomainUpDown control in code. Call the Add or Insert method of the DomainUpDownItemCollection class to add items to the control's Items property. The Add method adds an item to the end of a collection, while the Insert method adds an item at a specified position.

To add a new item

  • Use the Add method to add an item to the end of the list of items.

        Private Sub DomainUpDown1_SelectedItemChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DomainUpDown1.SelectedItemChanged

            DomainUpDown1.Items.Add("New York")
            DomainUpDown1.Items.Add("India")
            DomainUpDown1.Items.Add("USA")

        End Sub

    Output :

    image1.gif

Removing Items from DomainUpDown Controls
 
You can remove items from the Windows Forms DomainUpDown control by calling the Remove or RemoveAt method of the DomainUpDownItemCollection class. The Remove method removes a specific item, while the RemoveAt method removes an item by its position.

To remove an item

  • Use the Remove method of the Items collection to remove an item by name.

            DomainUpDown1.Items.Remove("New York")
            DomainUpDown1.Items.Remove("India")
            DomainUpDown1.Items.Remove("USA")

Login to add your contents and source code to this article
share this article :
post comment
 
Nevron Diagram
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Become a Sponsor