Your Ads Here

Contact Us

Contact Us
Email
: sivodayatech@dotnetdevelopertool.com

Monday, 7 May 2012

Working of ListBox control in VB.NET

It shows the working of ListBox control in VB.NET
Keywords: VB.NET, Visual Basic.NET, ListBox

1) To add items to the ListBox (Default Items)
 
ListBox1.Items.Add("FirstItem")
ListBox1.Items.Add("FirstItem2")

2) To add items to the ListBox (from TextBox)
 
ListBox1.Items.Add(TextBox1.Text)

3) Count the no of items in the ListBox

TextBox1.Text = ListBox1.Items.Count
 
4) Add items to the specified index of ListBox

ListBox1.Items.Insert(1, "Hello") ' 1-index
'or
ListBox1.Items.Insert(1, TextBox1.Text)

5) To clear ListBox items

ListBox1.Items.Clear()

6) To get selected item of the ListBox
 
TextBox1.Text = ListBox1.Text
'or
TextBox1.Text = ListBox1.SelectedItem


7) Get selected items through index 
 
TextBox1.Text = ListBox1.SelectedIndex
'or
TextBox1.Text = ListBox1.Items.Item(2)

8) To remove a selected item from the ListBox
 
ListBox1.Items.Remove(ListBox1.SelectedItem)

9) Remove selected item using index

ListBox1.Items.RemoveAt(2)
'or
ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)

More Topics:


Note: If you have any suggestions or any new topics to post, please contact us Our Mail ID: sivodayatech@dotnetdevelopertool.com