ARTICLE

NumericUpDown and DomainUpDown control in vb.net

Posted by Dea Saddler Articles | ASP.NET using VB.NET March 18, 2011
In this article we demonstrate what is NumericUpDown and DomainUpDown Control and how to use both the Controls
Reader Level:


A visual basic NumericUpDown control is said to be a pair of a TextBox Control and the Up Down arrows. The NumericUpDown Control generally works as a counter in which a user can input a numeric value. It is also called a Spin box. The arrow in the NumericUpDown Control works for increase or decrease the value. Up arrow is for increase the value and down arrow is for decrease the value. If you hold the mouse on the up arrow it will increase the value till the maximum value in the list and then stop. Its reverse condition is works with the down arrowthe Specific range is also defined for the values. The example for the NumericUpDown Control is the Volume control in any Music Player.

The below example shows the use of NumericUpDown control:-

  • Create a new Project 
  • Add a NumericUpDown control, a Label and a Button. The form will look like below.

    NumericUpDown1.gif
     
  • Add the below code to the form.

    Public Class Form1
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
           
    Button1.Click
            Me.Close()
        End Sub
        Private Sub NumericUpDown1_ValueChanged(ByVal sender As System.Object, ByVal e As                System.EventArgs)
        Handles
    NumericUpDown1.ValueChanged
            Label1.Text = "The current Value of the counter is : " & NumericUpDown1.Value
        End
    Sub
    End Class

    Output:-

    NumericUpDown2.gif

    DomainUpDown Control:-

    DomainUpDown control is used to allow user to move up or down to a particular value. It shows a textbox and up and down arrow that allows user to move between its values. The DomainUpDown control Shows and sets a text string from a given list of choices. If you want to select a string you can do this by up and down buttonand also by typing the string in the TextBox that matches the string in the list.

    The below example shows the use of DomainUpDown control:-
     
  • Create a new project. 
  • Add TextBox, CheckBox and two Buttons than form will look like below.

    DomainUpDown1.gif
     
  • Add the Below code to the form.

    Protected WithEvents domainUpDown As DomainUpDown
     
            Private myCounter As Integer = 1
             Private Sub MySub()
             domainUpDown = New System.Windows.Forms.DomainUpDown()
             Controls.Add(domainUpDown)
             End Sub
     
            Private Sub button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
            
    Button1.Click
             domainUpDown.Items.Add((TextBox1.Text.Trim() & " - " & myCounter))
                 myCounter = myCounter + 1
                 TextBox1.Text = ""
     
            End Sub
     
            Private Sub checkBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
            
    CheckBox1.CheckedChanged
             If domainUpDown.Sorted Then
     
                domainUpDown.Sorted = False
     
            Else
     
                domainUpDown.Sorted = True
     
            End If
     
            End Sub
     
            Private Sub domainUpDown_SelectedItemChanged_(ByVal sender As System.Object, ByVal e As
            
    System.EventArgs)
             MessageBox.Show(("SelectedIndex: " & domainUpDown.SelectedIndex.ToString() & _
             ControlChars.Cr & "SelectedItem: " & domainUpDown.SelectedItem.ToString()))
             End Sub
     
            Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
             MyBase
    .Load
                 MySub()
             End Sub
     
            Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
                
    Button2.Click
                 Me.Close()
             End
    Sub


    Output:-

    DomainUpDown2.gif

    DomainUpDown3.gif



Login to add your contents and source code to this article
share this article :
post comment
 
Become a Sponsor
PREMIUM SPONSORS
  • The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Become a Sponsor