Results 1 to 5 of 5

Thread: How to create ListBox in VB.net?

  1. #1
    Join Date
    Aug 2006
    Posts
    139

    How to create ListBox in VB.net?

    I am very new to the Programming Language. I have started learning VB.Net recently. Now I am trying to make a form which requires a ListBox into it. Does anyone know how to create ListBox in VB.Net.?? Please tell me as I am newbie in the programming languages.!! Also if possible provide some more codes.! I am hoping for the help as soon as possible.
    The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little.
    -Joe Martin

  2. #2
    Join Date
    May 2008
    Posts
    2,012

    Re: How to create ListBox in VB.net?

    You can use the following steps to program Listbox Functionality in VB.net :
    • First create a new windows application after opening the VB.net application.
    • In your blank form, add a listbox, two buttons and a textbox.
    • Then change the text property of the first button to "Add".
    • After that change the text property of the second button to "Remove".
    • Now to bring up the button's click event, double-click on the "Add" button.
    • Here you will have to add the codes for the adding the items in listbox.
    • Do same thing for the remove button.
    • Lastly run the program by pressing the F5.
    • Type something into the textbox then click the "Add" button. You will see that it has been added to the listbox. Now click on the item in the listbox and click the "remove" button. You will notice that the item has been removed.

  3. #3
    Join Date
    Apr 2008
    Posts
    2,005

    Re: How to create ListBox in VB.net?

    You can use the following guides for creating the ListBox in VB.net :
    For creating a new VB.NET Windows forms ListBox, you can use the code \
    Code:
    Dim listbox As New ListBox
    If you want to assign a new location for the VB.NET Windows Forms ListBox you can use :
    Code:
    listbox.Location = New Point(0, 0)
    If you want to add a VB.NET ListBox control to the form, you can do by
    Code:
    Me.Controls.Add(listbox)
    For assigning a Selection Mode value to the VB.NET ListBox control, use
    Code:
    listbox.SelectionMode = SelectionMode.MultiExtended
    Mainly, you need to add an item to the ListBox control in Vb.Net and you can do this by using the code :
    Code:
    Dim s1 As String = "DELL"
    Dim s2 As String = "HP"
    Dim s3 As String = "SONY"
    listbox.Items.AddRange(New String() {s1, s2, s3})

  4. #4
    Join Date
    May 2008
    Posts
    2,297

    Re: How to create ListBox in VB.net?

    For making a selection of items we make the ListBox control. THe advantage of making the ListBox Control is that we can select one or more than one of the items from the list. The ListBox control is based on the ListControl class which is based on the Control class. The SelectedIndexChanged is the default event of ListBox, which looks like the following code :
    Code:
    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
    
    End Sub

  5. #5
    Join Date
    Nov 2008
    Posts
    996

    Re: How to create ListBox in VB.net?

    If you want to display the index of an item you can use the following code :
    Code:
    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
    TextBox1.Text = ListBox1.SelectedIndex
    'using the selected index property of the list box to select the index
    End Sub
    Also if you want to display the item selected from ListBox in a TextBox, you can use the following code :
    Code:
    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object,_
    ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
    TextBox1.Text = ListBox1.SelectedItem
    'using the selected item property
    End Sub

Similar Threads

  1. How can I add a Listbox header using VBA in Excel
    By FullTimepass in forum MS Office Support
    Replies: 2
    Last Post: 25-01-2012, 04:55 PM
  2. ListView or ListBox
    By Heather5 in forum Software Development
    Replies: 3
    Last Post: 29-08-2009, 12:10 AM
  3. C# Listbox control
    By abhinavm in forum Software Development
    Replies: 2
    Last Post: 07-08-2009, 11:01 PM
  4. ListBox Drop down menu in vb.net
    By SamsherR in forum Software Development
    Replies: 3
    Last Post: 16-02-2009, 04:46 PM
  5. I have a problem with listbox
    By StoaVio in forum Software Development
    Replies: 2
    Last Post: 25-10-2008, 03:33 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,522,951.79712 seconds with 16 queries