Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 22-01-2010
Member
 
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
Reply With Quote
  #2  
Old 22-01-2010
Member
 
Join Date: May 2008
Posts: 2,008
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.
Reply With Quote
  #3  
Old 22-01-2010
Member
 
Join Date: Apr 2008
Posts: 2,001
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})
Reply With Quote
  #4  
Old 22-01-2010
Member
 
Join Date: May 2008
Posts: 2,293
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
Reply With Quote
  #5  
Old 22-01-2010
Member
 
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
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How to create ListBox in VB.net?"
Thread Thread Starter Forum Replies Last Post
How can I add a Listbox header using VBA in Excel FullTimepass MS Office Support 2 25-01-2012 04:55 PM
ListView or ListBox Heather5 Software Development 3 29-08-2009 12:10 AM
C# Listbox control abhinavm Software Development 2 07-08-2009 11:01 PM
ListBox Drop down menu in vb.net SamsherR Software Development 3 16-02-2009 04:46 PM
I have a problem with listbox StoaVio Software Development 2 25-10-2008 03:33 PM


All times are GMT +5.5. The time now is 01:13 PM.