Create a listener to save grid state