The twin grain boundary can favor the formation of the Co-Co dimer in Co-doped ZnO. The dimer in FM state is 0.18 eV higher than that in AFM state. The twin grain boundary can mediate the FM coupling between the dimers. Due to the sructural character of the twin grain boundary, the macroscopic FM ordering is expected.