Sorry to hear about your cucumber disappointment

Their eggs hatch after a couple of days, so I shouldn't think they're in the bagged up compost, sounds more like they're laying them in your soil, when you sow your seeds. So preventing the flies laying eggs might be the answer.
This website
http://www.just-green.com/Article/181/Scarid-Flies-or-Fungus-Gnats.htmlsuggests a layer of perlite or grit to prevent the flies getting to the soil to lay eggs.
And it also suggests sticky traps, which might be an option if you're sowing in a greenhouse. Maybe not if you keep your seedlings in your bedroom
