actually, what you're looking for is the function to align objects to each other. snap to grid will only work for your purpose in certain situations, like when the connected objects are of equal hight/width, or when the line is connected to the snapped edge.
it's better to align the objects vertically or horizontally. if the line is connected in the middle of the objects, center the alignment. if the line is connected in the right edge of the objects, and they are stacked vertically, use right aligned vertical alignment :)
if i remember correctly, the options for alignment can be found in the object menu. it's definitely in one of the left most menus, in the bottom! i'll update this as soon as i'm at my computer again.