Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to prevent ItemCheck event from firing

Status
Not open for further replies.

tshad

Programmer
Jul 15, 2004
386
US
If I have a CheckedListBox with an ItemCheck event defined, how do I set it to fire only if a user actually selects a checkbox item not when I check it programmatically.

Right now, if I programmatically set all the checkboxes, I will enter the event code 10 times if I have 10 checkbox items.

I don't want it to fire at all here.

But when the user selects a checkbox, then I want it to fire.

Thanks,

Tom
 
Assuming you have a method to perform some action when the checkbox is selected - perhaps called "checkbox1_CheckedChanged", the following should point you in the right direction.

Code:
private void CodeToDoWork()
{
    checkbox1.CheckedChanged -= checkbox1_CheckedChanged;
    //Your work goes here
    checkbox1.CheckedChanged += checkbox1_CheckedChanged;
}

Basically, the first line "removes" the event that you do not want fired when you change the state of the checkbox. You do the work you want to do. Finally, the last line "connects" the event back up to the CheckedChanged code.

I actually use the "+= some_event" a lot to assign the events to my controls on my Form_Load event because I do a lot of pre-processing and populating the screens before I want the fields to have any actionable events.

Robert "Wizard" Johnson III
U.S. Military Vets MC
CSM, CSPO, MCPD, CCNA, CCDA, MCSA, CNA, Net+, A+, CHDP
Senior Database Developer
 
That is exactly what I want to do.

But I have about 10 ChecklistBoxes that I want to pre-process but don't want the event to fire.

Is there a way to query the object (CheckListBox) to find out what the event handler for an event is so I can take it off and back on again. I want to run it from one method that just passes in the object and the object will stop the event, set some checkboxes in the object and then turn the event back on.

Thanks,

Tom
 

Would my answer to your question from thread796-1765835 work for you?

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
It would.

I did answer it a few minutes ago.

Thanks,

Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top