Writing selected items from listbox to textbox

lotus18
02-13-2008, 08:35 AM
Hello world!!!

How can I write all the selected item of the listbox to a textbox? For e.g. I have these items from a listbox:

-rey
-john
-jane
-mike
-ken
-blen

If I selected rey and jane, the output of the textbox should be rey, jane else the output is All
By the way, my listbox's style is 1-Checkbox.

This is my sample code

Code:

Private Sub cmdOK_Click() If chkAll.Value = 1 Then txtName.Text = "All" Else txtName.Text = lstNames.Text End If


Please guide me. thanks

tHuNd3r
02-13-2008, 09:14 AM
I would check for the Selected on each item, and if one of them is not Selected, them, they are not "all selected", and as i do this i create the string writing on the textbox...


Dim n As Long, bAll As Boolean

bAll = True
Text1.Text = ""
For n = 0 To List1.ListCount - 1

If List1.Selected(n) Then
If Text1.Text <> "" Then
Text1.Text = Text1.Text & ", "
End If
Text1.Text = Text1.Text & List1.List(n)
Else
bAll = False
End If

Next

If bAll Then
Text1.Text = "All"
End If

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum