I was in the hospital getting a sleep study done a few weeks ago. They involved putting a bunch of electrodes on my scalp and other places.
The first time I went through this, they had me keep my hair loose but told me not to fuss with it so that I wouldn't disturb the electrodes. This time, I suggested that they tie my hair back with the wiring bundle attached. After some thought, the tech pulled out this stretchy bandage product that he wrapped around my hair a few times.
It worked great! Not only did it and my hair stay in place all night, but in the morning it came out with no lost hair at all.
So if you've got to have something similar done, check to see if they have the same product available. I also noticed after looking for it on-line so that I could properly reference it that the material comes in a variety of colours and styles - perhaps it would be good for every-day too if only I can lay in a supply.
I had a similar sleep study done a few years ago and my long hair was an issue as well. They let me keep my hair tied back in a ponytail and the tech said my hair actually helped keep the electrodes in place.
I've used that type of bandage before, but not for my hair. I used it to reinforce my wrists while playing football (American football). I'll have to see if I have any left and give it a shot with my hair.