Handling problem with ListView.ItemCheck event

  • Thread starter Mike Ruane-Torr
  • Start date
M

Mike Ruane-Torr

I have a design problem involving a ListView control on a Windows form.
What it boils down to is the following question:

Q: Is there a way to tell the difference between a ListView.ItemCheck
event that has occurred because of a mouse click on a Checkbox, and one
that has occurred because the .Checked property of an item has been
changed programatically?

More details if needed, but if you can answer the above, you'll have
solved the problem! :)
 
C

Charles Law

Hi Mike

I use the Infragistics components, and there is a BeforeCheck event.

What I am doing is allowing code to change the check state, but not the user
by clicking an item.

The way I got round the problem you illustrate is to implement the
BeforeCheck handler and always cancel the attempt to check/uncheck the box.
Then, in the code that is allowed to change the state, I remove the handler,
change the state, and then add the handler again. A bit crude, but it works.

Alternatively, set a flag before you make the change in code, and test the
flag in the BeforeCheck event.

One other possibility is that check boxes have an AutoCheck property. If you
set that to false it allows you to control when the check box is checked.

HTH

Charles
 
M

Mike Ruane-Torr

The way I got round the problem you illustrate is to implement the
BeforeCheck handler and always cancel the attempt to check/uncheck the
box.
Then, in the code that is allowed to change the state, I remove the
handler,
change the state, and then add the handler again. A bit crude, but it
works.
I considered this kind of approach, but thought that it might not be
thread-safe. Perhaps I should try it.
Alternatively, set a flag before you make the change in code, and test
the
flag in the BeforeCheck event.
I think that would definitely NOT be thread-safe.
 

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