Solved

check boxes in list control

Posted on 2000-02-29
7
163 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

809 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