@EgoMoose made a really good tutorial on grid placement systems. I recommend that you check it out as it has a section with the “lock to grid” functionality that you need.