This paper proposes a novel control for voltagesource inverters with the capability to flexibly operate in gridconnected and islanded modes. The control scheme is based on the droop method, which uses some estimated grid parameters such as the voltage and frequency and the magnitude and angle of the grid impedance. Hence, the inverter is able to inject independently active and reactive power to the grid. The controller provides a proper dynamics decoupled from the grid-impedance magnitude and phase. The system is also able to control active and reactive power flows independently for a large range of impedance grid values. Simulation and experimental results are provided in order to show the feasibility of the control proposed.