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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Row Height in GridDataBoundGrid with user control not working

Thread ID:





78470 Dec 15,2008 01:24 PM UTC Dec 18,2008 05:00 AM UTC WinForms 5
Tags: GridControl
Schneider Leah
Asked On December 15, 2008 01:24 PM UTC

I have a GridDataBoundGrid bound with two levels of hierarchy.
I have a user control bound to the second level column.
I want to get the rows with user control resized according to controls's height and width.
I'm using:
//Call ResizeToFit which in turn calls OnQueryPreferredClientSize method in the cell this.PEGrid.Model class
//in order to retrieve the Correct size of the controls in grid cells and adjust respective
//RowHeights & ColWidths in order to make the cells to fit controls.
this.PEGrid.Model.RowHeights.ResizeToFit(GridRangeInfo.Table(),GridResizeToFitOptions.NoShrinkSize); //GridRangeInfo.Table() PEGrid.ViewLayout.VisibleCellsRange,
this.PEGrid.Model.ColWidths.ResizeToFit(GridRangeInfo.Table(), GridResizeToFitOptions.NoShrinkSize); //GridRangeInfo.Table()

The following method appears in CellModel class:
protected override Size OnQueryPrefferedClientSize(Graphics g, int rowIndex, int colIndex, GridStyleInfo style, GridQueryBounds queryBounds)

//Calculate the size of the control
MyControl userControl = Grid[rowIndex, colIndex].Tag as MyControl;

//Calculate the size of the control
Size size = userControl.Size;
size.Height +=2;
size.Width += 2;

return size;

It works for column width but not for rows height.
If I stick my user control to a column in the root tables of the dataset, it shows up correctly.
Please help!

Jisha Joy [Syncfusion]
Replied On December 16, 2008 11:34 AM UTC

Hi Leah,

Please refer the following sample in our browser sample in the following location:

..\\My Documents\Syncfusion\EssentialStudio\\Windows\Grid.Windows\Samples\2.0\GridLayout\CustomCellAutosizing\cs

This sample shows how to automatically resize the grid cells depending upon the size of the custom controls that are placed inside the cells.


Schneider Leah
Replied On December 16, 2008 12:45 PM UTC

Hi Jisha,
This is exactly what I'm using. I attached my example. In this example I have a dataset of two related table:parent and child.
Then I'm removing some columns from the layout and defining a user control in one of the columns of the parent data table.
Still when resizing event fires it works only for column width and not the height.
What do I do wrong?


Jisha Joy [Syncfusion]
Replied On December 17, 2008 09:35 AM UTC

Hi Leah,

The issue can be resolved by setting the SmoothControlResize property to true. Please see the code:

this.gridDataBoundGrid1.SmoothControlResize = true;


Let me know if this helps.


Schneider Leah
Replied On December 17, 2008 12:40 PM UTC

Hi Jisha,
It helped but here we had a control bound to the first table. Here's my slightly changed example attached - control is bound to the second table, and it doesn't work.
Thanks, Leah


Jisha Joy [Syncfusion]
Replied On December 18, 2008 05:00 AM UTC

Hi Leah,

Thank you for the modified sample.

Please subscribe the paint event of GridDataBoundGrid as shown below:

this.gridDataBoundGrid1.Paint += new PaintEventHandler(gridDataBoundGrid1_Paint);

void gridDataBoundGrid1_Paint(object sender, PaintEventArgs e)

this.gridDataBoundGrid1.Paint -= new PaintEventHandler(gridDataBoundGrid1_Paint);
gridDataBoundGrid1.Model.RowHeights.ResizeToFit(GridRangeInfo.Rows(1, this.gridDataBoundGrid1.Model.RowCount),



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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon 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.Close Icon