Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LixtBox - Visual Basic 6.0

Status
Not open for further replies.

Danielvb

Programmer
Oct 8, 2002
34
US
Hi programmers:

Version: Visual Basic 6.0

I need help with a listbox which Style is 1-checkbox. when the program opens the listbox gets

populated by 50 states. I have three buttons:

1- to select and unselect one more states
2- Select All - to check or select all states
3- Unselect All - to uncheck or unselect all checkboxes

Note:

Case 1:
If I run the program by opening it throughtout Microsoft Visual Basic the program runs without no

problem.


Case2:
If I compile the program and I make it an executable, the program does:
-- populate the listbox wiht the 50 states names
-- I able to select one state and process
-- I am not able to execute multiple selections
-- I am not able to use the SELECT ALL or UNSELECT ALL because the program cancel and close

completed.

Could you please tell me what I am doing wrong.

Thanks all for your time.


Daniel
Florida

===========================================
Here is the code for for the three buttons:


Private Sub SelectState_Click()
FromButton = True
ListboxS.Selected(ListboxS.ListIndex) = Not ListboxS.Selected(ListboxS.ListIndex)
End Sub


Private Sub cmdSelectAll_Click()
Dim i As Integer
For i = ListboxS.ListCount - 1 To 0 Step -1
If ListboxS.Selected(i) = False Then
ListboxS.Selected(i) = True
End If
Next i
End Sub


Private Sub cmdUnselectAll_Click()
Dim i As Integer

For i = ListboxS.ListCount - 1 To 0 Step -1
If ListboxS.Selected(i) = True Then
ListboxS.Selected(i) = faalse
End If
Next i
End Sub

 
maybe it's a typo but in your cmdUnselectAll_click sub you wrote listboxS.Selected(i) = faalse...

Second note is that I think you don't need to check if something is selected or not to select or unselected...

Private Sub cmdUnselectAll_Click()
Dim i As Integer
For i = ListboxS.ListCount - 1 To 0 Step -1
ListboxS.Selected(i) = False
Next i
End Sub

This is just a design-tip... it should work perfectly the way you wrote it...

greetz

Mim
 
Check if Multiple Selections (MultiSelect) Property has been enabled for the list box.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top