Changes to the QueryOverride must be made before CreateChildControls is called. Thus it can either be done on databinding or in an override of CreateChildControls before base.CreateChildControls is called.
ContentByQueryWebpart QueryOverride from code
14/01/2011