Grid does not autosize

Apr 6, 2009 at 9:34 PM

Hi

When I set the grid's autosize property to true, the grid does not grow to fit the content. Autosizemode is growonly, i have tried growshrink, but no luck.

Apr 8, 2009 at 1:28 PM
Do you have this in your code after the cells have been filled?

this.AutoSizeCells();

David
Apr 8, 2009 at 4:29 PM
Nope I dont, why
Apr 9, 2009 at 7:49 AM
Because that forces a resize of the cells to their contents.
Apr 9, 2009 at 2:56 PM

Just to clearify one thing for myself.

AutoSizeCells should do this:    Fit the number of cells created into the grid control no matter what

?????????

In the code below I have

myGrid.AutoSizeCells();

but it only autosizes the columns to fit, and it leaves white margin next to it, it does not work for the rows. I still get a scrollbar for the rows.

namespace WindowsFormsApplication1

{
class clsGrid
{
public const int DEFAULTNUMBEROFROWS =20;
public const int DEFAULTNUMBEROFCOLUMNS = 20;

public clsGrid(SourceGrid.Grid myGrid,int frmHeight,int frmWidth)
{
myGrid.Redim(DEFAULTNUMBEROFROWS, DEFAULTNUMBEROFCOLUMNS);
SourceGrid.Cells.Views.Cell view = new SourceGrid.Cells.Views.Cell();
view.BackColor = Color.Snow;

SourceGrid.Cells.Editors.TextBox TBEditor = new SourceGrid.Cells.Editors.TextBox(typeof(string));

myGrid.Redim(DEFAULTNUMBEROFROWS, DEFAULTNUMBEROFCOLUMNS);

myGrid.FixedRows = 1;
myGrid.FixedColumns =1;

for (int r = myGrid.FixedRows; r < myGrid.RowsCount; r++)
{
myGrid[r, 0] = new SourceGrid.Cells.RowHeader(r);
}

for (int c = myGrid.FixedColumns; c < myGrid.ColumnsCount; c++)
{
myGrid[0, c] = new SourceGrid.Cells.ColumnHeader(c);
}
myGrid[0, 0] = new SourceGrid.Cells.Header();

for (int r = myGrid.FixedRows; r < myGrid.RowsCount; r++)
{
for (int c = myGrid.FixedColumns; c < myGrid.ColumnsCount; c++)
{
myGrid[r, c] = new SourceGrid.Cells.Cell();
myGrid[r, c].Editor = TBEditor;
myGrid[r, c].View = view;
  1. myGrid[r, c].Value = r.ToString() + c.ToString();
}
}

myGrid.AutoSizeCells();
myGrid.Selection.Focus(new SourceGrid.Position(10, 10), true);


//myGrid.Width = frmWidth ;
//myGrid.Height = frmHeight ;

myGrid.Controller.AddController(new MyController());

}

}

}

Apr 9, 2009 at 3:46 PM
You can try:

myGrid.Columns.StretchToFit();
myGrid.Rows.StretchToFit();