I don't see anything in that code that is going to check or uncheck any items. That code is going to select all checked items and unselect all unchecked items. If you're seeing items get unchecked then that must be happening elsewhere.