Thanks all. Specifically Purma Jukka <jukka.purma at aalto.fi>, whose solution proved simplest to understand. I had thought that I needed to make the item selectable in order to move it. Not so. Removing the code that set that flag fixed everything.