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

How to use RowHeights.ResizeToFit

I am using a GridControl whose cells may contain varying numbers of lines of text. Can RowHeights.ResizeToFit be used to automatically adjust the height of each row based on the cell in that row containing the largest number of lines of text? When I use the RowHeights.ResizeToFit method, every row''s height is increased to the same height, which is several times taller than what is acutally needed. Thanks, --Van Baker

3 Replies

AD Administrator Syncfusion Team November 29, 2004 09:49 PM UTC

If I drop a GridControl and a button on a form, and add these two event handlers, the grid.RowHeights.ResizeToFit works as expected for me. private void Form1_Load(object sender, System.EventArgs e) { gridControl1[2,2].Text = "one\r\ntwo\r\nthree"; gridControl1[3,2].Text = "one\r\ntwo\r\nthree\r\nfour\r\nfive"; } private void button1_Click(object sender, System.EventArgs e) { this.gridControl1.RowHeights.ResizeToFit(GridRangeInfo.Cells(2,2,3,2)); } So, in your code do you have extra \r\n''s at the bottom of your strings in the cells? If so, this might explain the extra rowheight size. If you can post a sample showing the problem you are having, then we can try to spot why things are not working as expected?

VB vbaker November 30, 2004 09:31 PM UTC

Okay, using your example I''ve got it working--pretty much. I was making calls to both ColWidths.ResizeToFit() and RowHeight.ResizeToFit() inside a BeginUpdate()...EndUpdate() block which was where the grid structure was calculated and the cells and headers were populated. ColWidths.ResizeToFit seemed to be working fine but RowHeight.ResizeToFit() was as I reported above. When I moved the call to RowHeight.ResizeToFit _after_ EndUpdate, the resizing worked a lot better. Most of the time. However, the grid still occasionally "upsizes" the heights of rows where height adjustment is not needed. (Almost as if some rows "catch" the upsizing from the other rows.) I''ll try this with version 3 as soon as I''ve upgraded and see if that fixes it, unless you have some other insight into what I may have been doing wrong, or in the wrong sequence. Thanks, Van Baker

VB vbaker December 7, 2004 03:32 PM UTC

Hi Clay, It took me a little while to reproduce the problem with a "simple" example, but I finally have done so. It seems that the ResizeToFit problem happens when certain combinations of merged cells are present. My app uses two columns for row headers, the first of which contains two lines of text, and is merged with adjacent rows containing the same text. ResizeToFit seems to be picking up the "\n" in the header and applying that to the grid sizing. I extended your sample a bit to demonstrate the problem. Upon initial loading, the cells are too "tall". After clicking the button (using your same click event handler), the cells size down, but it may take several clicks to get them all the correct size. Code follows: private void Form1_Load(object sender, System.EventArgs e) { this.gridControl1[2,2].Text = "one\r\ntwo\r\nthree"; this.gridControl1[2,3].Text = "one\r\ntwo\r\nthree\r\nfour\r\nfive"; for (int row = 1; row < this.gridControl1.RowCount; row+=2) { this.gridControl1[row,0].Text = "Merged\nRow "+ row.ToString()+", "+(row+1).ToString(); this.gridControl1[row+1,0].Text = "Merged\nRow "+ row.ToString()+", "+(row+1).ToString(); this.gridControl1[row,1].Text = "Row " + row.ToString(); this.gridControl1[row+1,1].Text = "Row " + (row+1).ToString(); } this.gridControl1.Model.ColWidths[0] = 70; this.gridControl1.Cols.HeaderCount = 1; this.gridControl1.Cols.FrozenCount = this.gridControl1.Cols.HeaderCount; this.gridControl1.Model.RowHeights.ResizeToFit(GridRangeInfo.Rows(1, this.gridControl1.ColCount)); GridStyleInfo standardStyle = this.gridControl1.BaseStylesMap["Standard"].StyleInfo; standardStyle.MergeCell = GridMergeCellDirection.RowsInColumn; this.gridControl1.Model.Options.MergeCellsMode = GridMergeCellsMode.OnDemandCalculation|GridMergeCellsMode.MergeRowsInColumn; } ------- Sorry for the long post, --Van Baker

Live Chat Icon For mobile
Up arrow icon