views:

22

answers:

3

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.

A: 

You'd think that every grid API would have an optimal size setting but it usually doesn't. i've used a number of different grids that did not support such a feature. But, calculating the optimal size yourself isn't that tough. There's even code out there.

Check out this Code Project link.

Paul Sasik
Thanks for the links, but they seem to be about column sizing. 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.
EricSchaefer
+1  A: 

I don't think there exists such a command out of the box. So you have to do it on your own.

In this answer i already gave some hints about possible candidates you should consider by calculating the optimal size.

Oliver
+1  A: 

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

grid.width = grid.columns[0].width + grid.columns[1].width etc.

That just leaves the height of the grid which would be something like

grid.height = grid.rowHeight * numberOfRowsFromQuery + grid.headerRowHeight

of course you might want to put some sort of maximum height limit on that. All air-coded so property names will need checking.

Dan Iveson
That's what I am doing now. But what if the border width or something else changes in future framework versions, the calculation will be wrong. Oh, well..
EricSchaefer