Q:

Changing ListView.ShowItemToolTips raises ItemChecked events

Hi when I set ShowItemToolTips of a ListView with checkbox items to true in designer and change it to false in the code, the event ItemChecked is raised. The checked state itself is not changed though. But inside the (also raised) ItemCheck event the old value is not equal to the new value but the new value is the value that was previously visible. It seems like the items are re-inserted or reset in some way.
I tested this on two machines and projects. Why does this happen and how can I avoid it?

A:

I'll explain the "why", a workaround is hard to come by.  Some control properties are very impactful and can have odd side-effects when you change them.  Like ShowItemToolTips, changing it after the ListView is created requires Winforms to completely destroy the native control and recreate it from scratch.  Under the hood, it is a style flag (LVS_EX_INFOTIP) that's specified in the CreateWindowEx() call.  The Control.RecreateHandle() method ensures it is effective.  You'll see the flicker that this causes if you look closely.
So for a brief moment, the native control exists without yet being initialized with the original checkbox states.  Getting a flaky event for that is a bug, but it is the kind that was either never fixed because doing so was too difficult or was just never discovered because nobody ever changes the ShowItemToolTips property after the control was created.  It is very uncommon to do so.
In general, this native control re-creation trick has been a significant bug generator in Winforms.  And workarounds are hard to come by, they fit either in the "deal with it" or the "don't do it" category.  With the latter one strongly recommended in this case.

