By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,122 Members | 927 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,122 IT Pros & Developers. It's quick & easy.

Adding elements to listbox

P: n/a
Hi

How can I programmatically add elements to a listbox?

Thanks

Regards

Nov 12 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"John" <Jo**@nospam.infovis.co.uk> wrote in message news:<3f*********************@news.dial.pipex.com> ...
Hi

How can I programmatically add elements to a listbox?

Thanks

Regards


John,

Below is code I have used in one of my forms for exactly this purpose

Public Sub CopyListItem(srcLBox As Control, trgLBox As Control)
'Copies selected items from one listbox to another
Dim ctl As Control
Dim varItem As Variant
Dim trgList As String
Set ctl = srcLBox

'Create a string by concatenating the selected items
For Each varItem In ctl.ItemsSelected
trgList = trgList & ctl.ItemData(varItem) & ";"
Next varItem
For Each varItem In ctl.ItemsSelected
Next varItem

'Set the string as rowsource for the target listbox
trgLBox.RowSource = trgList
trgLBox.SetFocus

'Deselect the items in the source list box
Dim intCurrentRow As Integer
For intCurrentRow = 0 To ctl.ListCount - 1
If ctl.Selected(intCurrentRow) Then
ctl.Selected(intCurrentRow) = 0
End If
Next intCurrentRow
End Sub
Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.