Develop a class and use that to maintain the grid.
I don't know what your implementation is or what you are trying to do so forgive me if the code is not what you need. Let's say you want a grid and you need each cell to turn a color or something. You can still use the recursive method I showed you, but instead of drawing vertices to the screen, you simply stick them in a vertex buffer or some type of array to contain the data. Notice that you still come out with the same result, but the generation code is about 50 times faster. It probably only took seconds to draw the grid using the code I gave you.
And to access a linear array in 2D you can use row*width+column. So if you know the width of your grid and one other variable you can find the offset into the array. If your vertex buffer is setup exactly as the grid appears then you can change the colors of the vertices at any point in the grid to create colored squares.
Write a class that controls the grid display.