The pilot reported the flight was uneventful until the landing gear failed to extend normally prior to landing at Quirindi. Normal and emergency procedures were unsuccessful. The aircraft then diverted to Gunnedah where ground observers reported the landing gear appeared to be extended, however, the right main gear collapsed during the landing roll. Investigation revealed an internal failure of the landing gear air/ground safety switch which rendered the gear door solenoid valve inoperative. The failure had apparently occurred during the initial landing gear extension cycle prior to the locking sequence of the right maingear. All subsequent hydraulic action was then directed to the selector handle lock valve, preventing completion of the landing gear extension cycle