Page 1 of 1

Extracting/Deleting multiple Items from listbox Using Loops, we are goin' to extract/Delete selected Icons from a Rate Topic: -----

#1 Nikhil_07n   User is offline

  • The cheese stands alone..
  • member icon

Reputation: 54
  • View blog
  • Posts: 2,490
  • Joined: 09-January 09

Post icon  Posted 23 January 2009 - 11:38 PM

Description : We are goin' to create 2 Listboxes, add some items in List1 at design time and then with cmdMove command button we'll copy selected items to list2.

Concept : This code checks the whole list(List1) through a for loop and then add the selected items to the other List2

NOTE : Make sure that the multiselect property of listboxes is '1-Simple'

Private Sub CmdcopyToList2_Click()
Dim i As Integer
If List1.SelCount = 1 Then
List2.AddItem List1.Text
For i = List1.ListCount - 1 To 0 Step -1
If List1.Selected(i) = True Then
List2.AddItem List1.List(i)
End If
Next i
End If
End Sub

Explanation : We are cheking selcount just for learning purposes(i.e, to learn the basic adding procedure).

If more then ONE items are selected, the loops checks each list item one by one and then adds the item if IT IS SELECTED.

NOTE : Step -1 is only for learning purpose, loop can be runned either way.


Private Sub CmdRemove_Click()
For i = List1.ListCount - 1 To 0 Step -1
If List1.Selected(i) = True Then
List1.RemoveItem (i)
End If
Next i
End Sub

Explanation : Just as the previous one, this too Removes the selected Items.

I Hope this helped

Is This A Good Question/Topic? 0
  • +

Replies To: Extracting/Deleting multiple Items from listbox

#2 nav234   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 18
  • Joined: 04-December 09

Posted 25 December 2009 - 07:06 AM


I need a listbox items not from collection items but from database .

Iam using 2008 and database - sql server 2005

Here in ,i have WPF page ,in tat iam not able to load items from database

can anyone help on this issue

thanks in advance


naveen... :rolleyes:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1