I think this may be what you're looking for. I'm using VB5.0 and have
been working on a project, part of which uses a listbox control with
checkboxes enabled. I set and clear these boxes through code. As you
doubtless know, each row in a listbox has an index number automatically
assigned to it.
Regardless of whether checkboxes are enabled for the listbox or not, the
method of programmatically selecting and deselecting the items (or rows) in
the listbox is the same--all you need do is specify the index number of the
item (or row) you want to select, and set the "selected" property to TRUE.
For example, let us assume your listbox is called "list1".
If you know which specific item you want to select, specify it's index
number in a statement like this:
list1.selected(5) = true
This would select (in the case of a listbox with checkboxes enabled, it
would "check") the fifth item in the list. If you don't know (or care)
about the specific index numbers of the items you want to check, you could
use an iterative construct. For example, I used the following in my own
code just today:
for i = 0 to list1.SelCount - 1 ' check each entry in the listbox
if list1.selected(i) = TRUE then list1.selected(i) = FALSE
next i
As you can see, all this does is race through the list, UN-checking every
item that the user checked. To make the code CHECK every item, you would
simply reverse the TRUE and FALSE values. Hope this helps. E-mail me and
let me know how it works for you.
Quote:
>If I set the listview control to have checkboxes, using LVS_EX_CHECKBOXES,
>how do I check one of the items in code? I have the code to retrieve if an
>item is checked, but I would like to know how to make an item checked from
>code?
>Thanks.
>-Dave