This project is read-only.

how to size cells width and height dinamically.

Aug 10, 2009 at 1:01 PM

I have only one column in the grid.

my grids column width is fixed.

my cells can have more than 1 lines of text.. WordWrap is enabled.

I would like to auto size the cell height so that its content should be visible at a time.

I want the function line control.TextHeight(string);

 

Thanks in advance..

Aug 10, 2009 at 1:07 PM
Hey,
 
The simple way, is to use a fixed size font, you then know how many pixels wide each character is, you know how wide your column is, so take your cell.Text.Length * pixel size, divide that by the width of the column and presto, you know how many rows you need.
 
Then just set the hight of the row to be font hight*number of rows needed.
 
You can call your resize function as an event on cell change, that way if someone types in text (or you programatically add text) your can fire your resize event ...
 
Hope that helps,
Derek

On Mon, Aug 10, 2009 at 8:01 AM, minchaudhary <notifications@codeplex.com> wrote:

From: minchaudhary

I have only one column in the grid.

my grids column width is fixed.

my cells can have more than 1 lines of text.. WordWrap is enabled.

I would like to auto size the cell height so that its content should be visible at a time.

I want the function line control.TextHeight(string);

 

Thanks in advance..

Read the full discussion online.

To add a post to this discussion, reply to this email (sourcegrid@discussions.codeplex.com)

To start a new discussion for this project, email sourcegrid@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com


Aug 21, 2009 at 7:17 AM

I'm not sure that I understand the question, but if you want to resize a cell manually, you can use the Graphics.MeasureString() function using a Rectangle to specify the columns width and you can get as out parameter the number of lines.

With SourceGrid you can call the function grid.AutoSizeCells() and specify a Range. If you've set a MinimalWidth to your cells, only the height will be affected.