combo box values

Values of ComboBox are can be read by using its items collection property. The example below uses a for each loop to iterate through the collection to read the values of ComboBox1 then add the values to ComboBox2 when a button is pushed.

Public Class Form1

   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
     Dim i As Integer = 0
     While i < 10
        ComboBox1.Items.Add(i) 'add items to ComboBox1
        i += 1

     End While
     ComboBox1.Text = 0 'show 0 in the box when the ComboBox1 displays

   End Sub

   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
     For Each item In ComboBox1.Items 'read values from ComboBox1
        ComboBox2.Items.Add(item) 'add values to ComboBox2
   End Sub
End Class

Posted by: Lavy | post date: 02-10-2013 | Subject: VB.NET Programming Language

This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.