AD
Administrator
Syncfusion Team
February 1, 2005 07:11 AM UTC
Try this code:
//total height
int h = this.grid.Model.RowHeights.GetTotal(0, this.grid.Model.RowCount + 1);
//width of, say, 5 columns
int w = this.grid.Model.ColWidths.GetTotal(0, 5);
this.grid.ClientSize = new Size(w, h);
If grid is a GriddataBoundGrid in the above code, there is some autosizing that is done at the initial display. If you want to control the size of the grid based on colwidths, then this autosizing will throw your calculations off. So, you would need to turn this off using grid.AllowAutoSize = false. You could also call grid.Model.ColWidths.ResizeToFit yourself if you still wanted the autozing after turning off the automatic autosizing at initial display, but you would want tto do it before the above code.
this.gridDataBoundGrid1.AllowResizeToFit = false;
this.gridDataBoundGrid1.Model.ColWidths.ResizeToFit(GridRangeInfo.Table(), GridResizeToFitOptions.IncludeHeaders);
//total height
int h = this.gridDataBoundGrid1.Model.RowHeights.GetTotal(0, this.gridDataBoundGrid1.Model.RowCount + 1);
//width of, say, 5 columns
int w = this.gridDataBoundGrid1.Model.ColWidths.GetTotal(0, 5);
this.gridDataBoundGrid1.ClientSize = new Size(w, h);