School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,368 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,446 people online right now. Registration is fast and FREE... Join Now!




Extracting/Deleting multiple Items from listbox

 
Reply to this topicStart new topic

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

Nikhil_07n
Group Icon



post 23 Jan, 2009 - 10:38 PM
Post #1


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'

CODE


Private Sub CmdcopyToList2_Click()
Dim i As Integer
If List1.SelCount = 1 Then
List2.AddItem List1.Text
Else
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.

REMOVING

CODE

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
Go to the top of the page
+Quote Post


Register to Make This Ad Go Away!


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 


Lo-Fi Version Time is now: 11/7/09 08:54PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month