Solved

check boxes in list control

Posted on 2000-02-29
7
168 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Industry Leaders: 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!

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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
Course of the Month6 days, 12 hours left to enroll

623 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