Where “optimal size” is “all rows and columns are visible, but not more“. (e.g. no dark gray background is visible)
Edit:
To clarify: I dont want to auto resize the columns. I have fixed width columns and rows. I want to have the whole control resized. e.g. reduce the width if there is dark gray space visible, increase the width if not all columns are visible, same for vertical space.
If you have fixed width columns then you should know how wide the grid is based on the number of columns returned by your query
That just leaves the height of the grid which would be something like
of course you might want to put some sort of maximum height limit on that. All air-coded so property names will need checking.