CheckListBox

  • Thread starter Thread starter john sutor
  • Start date Start date
J

john sutor

Does anyone know how to get the index of an item checked and then check it
if it is unchecked?
 
Not sure what your asking here. Why would you see if an item is checked,
then check it if it is not. That doesn't make sense.

Anyways,to get the selected index of an item in the collection.

int index;
index = checkedListBox1.SelectedIndex;



TJ. Reardon
 
Hmm.. That's kind of a strange question..
You say get the index of an item checked, then check it
if it is unchecked? The only way I can interpret this is:

Get the index of an item TO SEE IF IT IS checked, then
check it if not.

There are ways to do that, but my experiences with the
CheckListBox control are not necessarily good ones. I'm
still hoping that I can find a better way than what I have
written to manipulate that control.

Now, get this:

I wrote an application that was just perfect for the CLB
control, and it worked great. That is, until I started to
add options that I would like to have. What I wanted to
do was generate a set of data, populate the CLB with it,
and then (at my leisure) check the ones I wanted to keep
OR check the ones I wanted to discard. When the list is
very large, sometimes it's handier to check the ones you
want, and other times it's handier to check the ones that
you DON'T want. So, after I had checked either, I wanted
to write a routine to get rid of either the checked or the
unchecked. I went through all of the methods, properties,
etc. for hours without finding a simple way to do this. At
the end, I had to write some pretty complicated
algorithms to update the CLB with the items left from
either checked or unchecked. It wasn't fun and took a
very long time to figure out since there are no easy
built-in methods to do this. I did it, though, and you as
well might find that sometimes you have to do it the
hard way. I'm still thinking about publishing those
algoritms though, but I've been holding out just in case
there IS a simpler way to do it!
 
Hi,
Does anyone know how to get the index of an item checked and then check it
if it is unchecked?

I am afraid that your question is a little bit unclear (if you get the
index of a checked item, it doesn't make sense to verify if it is
unchecked, because you selected it to be checked).
Anyway, here a sample of how you could check an item if it was unchecked.

if (!this.checkedListBox1.GetItemChecked(index))
this.checkedListBox1.SetItemChecked(index, true);


Adrian Vinca [MSFT], Developer Division
--------------------------------------------------------------------
This reply is provided "AS IS", without warranty (express or implied).

Note: For the benefit of the community-at-large, all responses to this
message are best directed to the newsgroup/thread from which they
originated.
 
Back
Top