We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

resizing the grid

Hi... I need a little help with the auto resizing the GridGroupingControl

It seems that the control resizes itself only the first time I use the ResizeToFit method, and every other time it just stays the same.

I'm not sure what I'm doing wrong, so I've attached a simple example of the form.

Please modify it so the grid would resize itself every time. I need it to resize to the biggest cell in the column.
What I mean is: If I enter a text larger than any of the others, the column must fit to that text. Otherwise resize it to the next biggest cell.

Thanks in advance
Vicko

Resze.zip

3 Replies

JS Jeba S Syncfusion Team June 27, 2007 11:55 AM UTC

Hi Vicko,

Thank you for your sample.

Reason:
You try to set the short and long value in the second column(Col 2) but, in GridRangeInfo the column you are passing is the first one(Col 1).

Please refer this modified code and let us know if this helps.

private void button1_Click(object sender, EventArgs e)
{
gridGroupingControl1.Table.Records[0].SetValue("Col 2", "Text");
//Old code
gridGroupingControl1.TableModel.ColWidths.ResizeToFit(GridRangeInfo.Col(1), GridResizeToFitOptions.None | GridResizeToFitOptions.IncludeHeaders);
//New code
gridGroupingControl1.TableModel.ColWidths.ResizeToFit(GridRangeInfo.Col(2), GridResizeToFitOptions.None | GridResizeToFitOptions.IncludeHeaders);
}
private void button2_Click(object sender, EventArgs e)
{
gridGroupingControl1.Table.Records[0].SetValue("Col 2", "Looooooooooooooooooooooooooooooooooooooong text");
//Old code
gridGroupingControl1.TableModel.ColWidths.ResizeToFit(GridRangeInfo.Col(1), GridResizeToFitOptions.None | GridResizeToFitOptions.IncludeHeaders);
//New code
gridGroupingControl1.TableModel.ColWidths.ResizeToFit(GridRangeInfo.Col(2), GridResizeToFitOptions.None | GridResizeToFitOptions.IncludeHeaders);
}


Best Regards,
Jeba.


VH Vicko Hazdovac June 28, 2007 06:57 AM UTC

This does the exact same thing as before.

The column expands itself if the long text is entered, but if I set the text to back short it doesn't shrink to the next longest text.

(if I enter "Loooooooooong text" column should grow, but if I enter "Text" the column should shrink to "Some text")

How can I achieve this?


HA haneefm Syncfusion Team June 28, 2007 10:12 PM UTC

Hi Vicko,

You can try this code in button1's Click event.

gridGroupingControl1.TableModel.ColWidths.ResizeToFit(GridRangeInfo.Cells(5, 2, gridGroupingControl1.TableModel.RowCount , 2), GridResizeToFitOptions.ResizeCoveredCells);

Best regards,
Haneef


Loader.
Live Chat Icon For mobile
Up arrow icon