Checked Listbox?

D

dm1608

Hi, all.

I have a requirement for one of my programs to have a "Checked Listbox" that
contains a list of all my local/remote drives.

I woudl like users to click one or more drives that I need to search for
particular files.

Can anyone tell me how to implement this in .NET 2.0 using VB or C#?

I also need to know how to iterate thru the listbox to determine what items
are selected and extract there value property.

Thank you --
 
H

Herfried K. Wagner [MVP]

dm1608 said:
I have a requirement for one of my programs to have a "Checked Listbox"
that contains a list of all my local/remote drives.

Check out the CheckedListBox control.
 
G

Guest

I'd use a FileOpenDialog rather than a list box, it allows the user to drill
down and select exactly what they want, saving them time.

.... and how could you list "remote drives", if you mean mapped drives that's
one thing, but otherwise how can you know what drives are available -- the
FileOpenDialog would allow the user to select a drive on another machine
which your application wouldn't know about otherwise.

I think you're reinventing the wheel.
 
D

dm1608

Yeah, but I need them to be able to select multiple drive letters so my
application can scan for the relevent information.

I'm not sure how to use the Checked Listbox control and how to iterate thru
it
 
G

Guest

Which they can do with a FileOpenDialog, they can even select multiple
individual files.
 
G

Guest

Which they can do with a FileOpenDialog, they can even select multiple
individual files.

OK, I'm wrong again -- you can't use it to select directories :( I wish it
could, seems like some lacking functionality.

But my basic point is still valid, I would use an OpenFileDialog to allow
the user to select exactly which files to use.

And consider this: if your application doesn't want to allow the user to
know what files are in use then I don't know why they should know and select
_where_ they are either.
 
G

Guest

How about a FolderBrowserDialog? Although it doesn't seem to allow selection
of multiple directories :(
 
D

dm1608

Thanks -- but I think I really want them to select drives and not even have
the ability to select folders.

Drives are really all I need. I.E., they want to search C: drive and D:
drive. Then they'd select both. Otherwise, they would select C: only or
whatever.
 
L

Lawrence R. Steeger

Thanks -- but I think I really want them to select drives and not even have
the ability to select folders.

Drives are really all I need. I.E., they want to search C: drive and D:
drive. Then they'd select both. Otherwise, they would select C: only or
whatever.

...

Checkout the DriveInfo class (new in .NET 2.0).
 
B

Bernie Hunt

It fairly straight forward. To load the box you add to the Items list and
include it the item is checked by default or not. The code looks like
this

clbVendorShows.Items.Add("E:", False)

You will need to get a list of all the drives in the system and customize
the statement with what you want it to list. You will have one of theses
statements for each item in the checkedlistbox.

Note: If you want to reselect an item, the use;
clbVendorShows.Items.Add("C:", True)

To read back you use
isChecked = clbVendorShows.GetItemChecked(i)
where i is the index into the items.

Here's some code I just used to step through all the items in the box to
see if they where checked.
For i = 0 To clbVendorShows.Items.Count - 1
isChecked = clbVendorShows.GetItemChecked(i)
' do some other things here based on what I found ...
Next

There are other ways to reach what is checked, in my case I needed to
know what was check and what wasn't. Read up on the documentation in VS,
on the collections available. There is one for "checked" items that will
return all the items that were checked. That would be handy for when you
just care about what was selected and not what wasn't selected.

Bernie
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top