Solved

check boxes in list control

Posted on 2000-02-29
7
160 Views
Last Modified: 2010-05-02
ok this must be easy.... but for some reason im doing something wrong. I have some checkboxes in a list control (one of the properties), but i dont know how to automatically turn them on and off.
0
Comment
Question by:TCPIP2600
  • 5
  • 2
7 Comments
 
LVL 1

Accepted Solution

by:
PatrickVD earned 10 total points
ID: 2570992
The property of the listbox that makes the checkboxes appear is the Style property and takes the values  0 for standard, 1 for checkboxes.

Now if you're looking on how to set an item in the listbox with the checkbox marked or not marked, you have to look at the Selected property of the listbox :

    List1.AddItem "Item 1 - Not Checked"

    List1.AddItem "Item2 - This one is checked"
    List1.Selected(List1.NewIndex) = True

This should answer your question...
0
 
LVL 3

Expert Comment

by:Gordonp
ID: 2572129
You cannot set the Check from code, and the only way to get the current checked status of a list entry is to monitor all the ItemCheck events.

The Selected property only tells you if the item is selected, not whether its checked or not.

If you want to programatically set the state of the Check box you should use the listview control instead. Slightly more complicated to use, but not too heavy on the old brain cells.

Gordon.
0
 
LVL 1

Expert Comment

by:PatrickVD
ID: 2572276
Sorry Gordon... but I think you're mistaking....

If you use a standard listbox and set its Style property to 'Check Box (Value = 1) the Selected property of the listbox will automatically reflect the state of the checkmark. If you set it to True it will be checled, and the checkmark will be unchecked if you set its value to False....
This means that you can set the state of the checkbox programmatically !

To proove you just try the following :

Create a standard exe in VB6, add a listbox List1 to the form and a Command button Command1.
No copy and paste this code in your form's code window and run it....
When its running in debug mode, try to click around on the listbox items by changing the state of the checkboxes... and press the Command1 on each change...


---CODE TO COPY

Private Sub Command1_Click()

    Dim strSelected As String
    Dim i As Integer
   
    For i = 0 To (List1.ListCount - 1)

        If List1.Selected(i) Then
            strSelected = strSelected & "Item Selected = " & CStr(i) & vbCrLf
        End If

    Next i

    Debug.Print strSelected

End Sub

Private Sub Form_Load()
    'Just create some entries in the listbox to have it filled...
    List1.AddItem "Checked"
    List1.Selected(List1.NewIndex) = True
    List1.AddItem "Not Checked"
    List1.AddItem "Checked2"
    List1.Selected(List1.NewIndex) = True
    List1.AddItem "Not Checked"
    List1.AddItem "Checked"
    List1.Selected(List1.NewIndex) = True
    List1.AddItem "Not Checked"
    List1.AddItem "Checked2"
    List1.Selected(List1.NewIndex) = True
    List1.AddItem "Not Checked"
    List1.AddItem "Checked"
    List1.Selected(List1.NewIndex) = True
    List1.AddItem "Not Checked"
    List1.AddItem "Checked2"
    List1.Selected(List1.NewIndex) = True
    List1.AddItem "Not Checked"
   

End Sub

---- END OF CODE

Try this and you'll see that it works...

Cheers,

Patrick.


0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 3

Expert Comment

by:Gordonp
ID: 2572376
Well, my mistake, and boy am I pissed off. So many things could have been so much simpler.

Gordon
0
 
LVL 3

Expert Comment

by:Gordonp
ID: 2572379
Well, my mistake, and boy am I pissed off. So many things could have been so much simpler.

Gordon
0
 
LVL 3

Expert Comment

by:Gordonp
ID: 2572381
Well, my mistake, and boy am I pissed off. So many things could have been so much simpler.

Gordon
0
 
LVL 3

Expert Comment

by:Gordonp
ID: 2572388
Well, my mistake, and boy am I pissed off. So many things could have been so much simpler.

Gordon
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now