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.

Derived cell control - auto expand the column width to fit control

Thread ID:





45444 Jun 21,2006 07:11 AM Jun 22,2006 04:14 AM Windows Forms 2
Tags: GridControl
Colin Bolton
Asked On June 21, 2006 07:11 AM

I have a custom cell type(implementing a GridGenericControlCellModel as in the calendar example) which contains a control whose size may change dynamically. Is there a simple way to automatically expand the width of the column to fit the size of the control if it is too small? Also if the user changes the column width I want to restrict the width to the size of the largest control in the column, is there a simple way (property to set?) or do I have to handle the column resizing events manually?? Cheers, Colin

Administrator [Syncfusion]
Replied On June 21, 2006 01:25 PM

Hi Colin, Regarding the Question 1: To resize the width of the column to fit the size of the control , you need to call the ResizeToFit method . Here is a code snippet. gridControl1.RowHeights.ResizeToFit(GridRangeInfo.Cell(2, 4)); gridControl1.ColWidths.ResizeToFit(GridRangeInfo.Cell(2, 4)); Note : this method only applicable for usercontrol celltype. If the celltype is control cell type , you need to caluclate the width of the control and assign the colWidth explictly. Regardig the Question 2: You need to handle the ResizingColumns event for preventing the resizing of the column in a grid. Here is a code snippet. private void gridControl1_ResizingColumns(object sender, GridResizingColumnsEventArgs e) { if(e.Columns.Left == 2) e.Cancel = true; } Let me know if this helps. Best Regards, Haneef

Colin Bolton
Replied On June 22, 2006 04:14 AM

Thanks Haneef, I think this does the job.


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.