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

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

2 Replies

AD Administrator Syncfusion Team June 21, 2006 05:25 PM UTC

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


CB Colin Bolton June 22, 2006 08:14 AM UTC

Thanks Haneef, I think this does the job.

Loader.
Up arrow icon