I've got a ListView which is normally hidden and Enabled=false;
I'm using the ItemChecked event Enable/Disable a button on the form (the button is disabled if nothing is checked)

If I add the ItemChecked event handler via the Designer in the usual way, it puts the code in the usual place and then when I enable the ListView it locks my app into an (apprently) infinite loop.
However, if I move the event handler assignment to a point AFTER the control is enabled, it works as expected.

I was just wondering if anyone can explain this behaviour... why is enabling a control with no checked items firing the ItemChecked event?

Put some boolean flag into the code, so you can say to the code when it can be used and when not - but you.

I mean something like:

bool bFlag = false;

void buttonEnable()//event of button
{
    bFlag = true;  // this will prevent firing the ItemChecked code in the 1st go-through
}

void ItemChecked() //event of listView
{
   if(!bflag)
   {
       // put yout code in this even in here...
   }
   else
       bFlag = false;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.