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

Row Height in GridDataBoundGrid with user control not working

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!


5 Replies

JJ Jisha Joy Syncfusion Team 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\6.3.0.30\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.

Regards,
Jisha



SL Schneider Leah 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?



hierarchy_636b11e7.zip


JJ Jisha Joy Syncfusion Team 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;

this.gridDataBoundGrid1.Model.RowHeights.ResizeToFit(GridRangeInfo.Table());
this.gridDataBoundGrid1.Model.ColWidths.ResizeToFit(GridRangeInfo.Table());

Let me know if this helps.

Regards,
Jisha



SL Schneider Leah 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




hierarchy2_f8fb2577.zip


JJ Jisha Joy Syncfusion Team 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),
GridResizeToFitOptions.None);
}

Regards,
Jisha


Loader.
Live Chat Icon For mobile
Up arrow icon