Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

check boxes in list control

Posted on 2000-02-29
7
Medium Priority
?
171 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 40 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

972 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