Moved code from Form to MainGrid