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.
Unfortunately, activation email could not send to your email. Please try again.

ResizeToFit ?

Thread ID:

Created:

Updated:

Platform:

Replies:

1307 Oct 15,2002 09:56 AM Nov 4,2002 09:31 AM Windows Forms 9
loading
Tags: GridControl
Mike Gorgone
Asked On October 15, 2002 09:56 AM

Hi All, I'm currently using the dbg to hold messages from a chat program. A row is added to the grid everytime a new message arrives. The grid is divided up into the following columns... time | from | to | message The from, to and message columns have varying length values and I'd like those columns to resize themselves to fit the data in the cell. I haven't been able to figure out the ResizeToFit method yet and I'm kind of lost here. Any Ideas? Thanks in advance for any help. Mike Gorgone

Administrator [Syncfusion]
Replied On October 15, 2002 01:54 PM

You would have to call the ResizeToFit each time you add a new row. So if your new row index in nRow, you could use code such as: this.gridDataBoundGrid1.Model.ColWidths.ResizeToFit(GridRangeInfo.Row(nRow), GridResizeToFitOptions.None); You would alos probably have to call ResizeToFit initially (say in the Form_Load event) to size things originally. > Mike Gorgone

Administrator [Syncfusion]
Replied On October 16, 2002 09:38 AM

You might want to use the GridResizeToFitOptions.NoShrinkSize option instead of the None option to avoid the size shrinking with a 'smaller' row.

Anthony Mansfield
Replied On October 31, 2002 12:52 PM

A followup to the original question. On a databound grid, If I set the AllowResizeToFit to true on the grid, should it resize to fit the contents when data is bound? Is this affected if the column widths are set manually prior the data being bound? How can I bind the data and have each of the columns resized to fit the width of the data? Thanks - Anthony

Administrator [Syncfusion]
Replied On October 31, 2002 03:49 PM

The AllowResizeToFit property only affects the resizing of the columns so the the headers fit. It does not take into effect the actual column contents. One way you can make sure all the text fits is to call ResizeToFit on the table at the end of your Form_Load after the DataSource has been set. this.gridDataBoundGrid1.Model.ColWidths.ResizeToFit(GridRangeInfo.Table, GridResizeToFitOptions.None);

Anthony Mansfield
Replied On November 1, 2002 01:09 PM

Thanks Clay. That works great and saves me a lot of trying to adjust the column widths. Anthony > The AllowResizeToFit property only affects the resizing of the columns so the the headers fit. It does not take into effect the actual column contents. > > One way you can make sure all the text fits is to call ResizeToFit on the table at the end of your Form_Load after the DataSource has been set. > > this.gridDataBoundGrid1.Model.ColWidths.ResizeToFit(GridRangeInfo.Table, GridResizeToFitOptions.None); >

John Sandberg
Replied On November 1, 2002 03:25 PM

I'm trying to get ResizeToFit() working on a bound grid of mine. The grid is holding 2000 records with 12 fields of data each. When I call ResizeToFit() from in my "click" even, it takes more than 10 seconds to refresh the grid, and the columns are not even properly resized. Any ideas on what I am doing wrong? Thanks, John

Administrator [Syncfusion]
Replied On November 1, 2002 05:30 PM

If you want to ResizeToFit 24,000 strings, it may take 10 seconds. You might try calling grid.BeginUpdate before your resizetofit call and grid.EndUpdate after your call, followed by a grid.Refresh call to make sure everything is redrawn properly. Also, make sure you don't have Undo buffer enabled as this will slow things done. But, you may want to consider just resizing the visible grid. This should take the 10 secs down to no secs. The grid.TopRowIndex and grid.ViewLayout.LastVisibleRow will give you access to the visible rows to pass into ResizeToFit.

John Sandberg
Replied On November 4, 2002 08:05 AM

I think I get it now. I was trying to figure out why manually d-clking on the header boarder would go so much faster; that's because it's only resizing to visible cell contents. Unfortunately. My users won't like that very much. Is there a way to only do column widths or any backdoor trick for making auto-widening of columns any faster (either bound or unbound)? I have to admit that 10 seconds isn't really industry standard here. Just about every other grid I've tested can do 10k cells in .3 secs or less. I appologize on bearing down on this point; it just ends up being a big thing for the product I am developing. John

Administrator [Syncfusion]
Replied On November 4, 2002 09:31 AM

John, Currently, Essential Grid visits every cell in the range to be resized, and calls MeasureString to compute exact sizes. If you want to speed things up, I think you will have to either reduce the number of cells being visited, or change the way the size is being computed. For example, if you know a column has a int in it, then you can easily come up with a max size for that column just by multiplying the average character size times the number of digits of the largest value you expect in the column. So, instead of visiting every cell in the column, you could do a quick calculation to set the column widths. Similarly, if it is a string column, and you know the max characters you expect, then you could calculate the maximum width, and not rely on visiting every cell. In such cases, the resize would be instantaneous. Or, if you are populating the grid directly, as opposed to binding to an external datassource, you could compute the maxsizes as you loop through the data initially, putting it into the grid. I suspect this is what Excel does to get the speed it has when resizing (as each piece of data is moved into Excel's internal data store, size calculations are done). This would lengthen the initial load, but speed up resizing. In both these situations, you would replace that calls to ResizeToFit with a call to your own method that uses special knowledge of the data to avoid having to visit every cell. If you want to tie into Essential Grid's resizing architecture, then you would have to derive from GridTextBoxCellModel and GridTextBoxCellRenderer, and override GridTextBoxCellRenerer.OnQueryPrefferedClientSize and do something other than measuring the string to find its length. When Essential Grid needs the optimal size of a size, it will call this method. It is this method that calls the measurestring as its default implementation. If you are willing to cut some corners like base the sizing on the same font, then you can speed things up. For example this code in a button handler sized 1000x10 cells between 1-2 seconds.
private void button1_Click(object sender, System.EventArgs e)
{
	int ticks = Environment.TickCount;
	this.gridControl1.BeginUpdate();
	Graphics g = Graphics.FromHwnd(this.gridControl1.Handle);
	for(int j = 1; j 

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;