Select a material across the bottom. Then click on an area of the grid to place that material.
Credit to @HugATurtle for the concept and the source project. I just used clones to reduce it to one sprite and clean it up a little.