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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ListBox Style Checkbox

Status
Not open for further replies.

keenanbr

Programmer
Joined
Oct 3, 2001
Messages
469
Location
IE
How do you set checkbox and check the value of the checkbox in a listbox whose style is 'checkbox'

thanks in advance
 
Take a look at the "Selected" Property.

If you choose to battle wits with the witless be prepared to lose.

[cheers]
 
Private Sub Command1_Click()
Dim i As Integer

For i = 0 To 2
List1.AddItem "ok"
List1.Selected(i) = True
Next i
End Sub
 
actually wht you need is

Private Sub Command1_Click()
Dim i As Integer

For i = 0 To 2
List1.AddItem "ok"
List1.Selected(0) = True
Next i
End Sub
 
To extend this question a more how would you then remove selected items in a listbox that has the checkbox style?

Sw0rdfish149
 
Code:
Private Sub Command1_Click()
Dim i As Integer

For i = 0 To 2
  If List1.Selected(i) Then List1.RemoveItem
Next i
End Sub

The style of the list box will not dictate how this is done it just controls how the selection is displayed (Check box or highlighted). Make sure your .multiselect property is set the way you want it.

Take Care,

zemp

"If the grass looks greener... it's probably because there is more manure."
 
Correct the code from my previous post,

Code:
...
    If List1.Selected(i) Then List1.RemoveItem(i)
...

Take Care,

zemp

"If the grass looks greener... it's probably because there is more manure."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top