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.

Row Height in GridDataBoundGrid with user control not working

Thread ID:

Created:

Updated:

Platform:

Replies:

78470 Dec 15,2008 08:24 AM Dec 18,2008 12:00 AM Windows Forms 5
loading
Tags: GridControl
Schneider Leah
Asked On December 15, 2008 08:24 AM

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 06:34 AM

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


Schneider Leah
Replied On December 16, 2008 07:45 AM


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

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

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


Schneider Leah
Replied On December 17, 2008 07:40 AM



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

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

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


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.

;