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

Resizing header only

Hi, How can I set the grid so that the user can only resize the column header vertically (only the first row must be resizable)? In the ResizeRowsBehavior I only see Syncfusion.Windows.Forms.Grid.GridResizeCellsBehavior.IgnoreHeaders which is the opposite of what I need to do. Thank

4 Replies

AD Administrator Syncfusion Team May 24, 2005 04:22 PM UTC

If you want to do special hit testing to decide exactly when you want to allow sizing, you should set the insidegrid flag in the ResizingCOlsBehavior property and handle the ResizingColumns event. Here is code that only allows resizing in row 1.
private void gridDataBoundGrid1_ResizingColumns(object sender, GridResizingColumnsEventArgs e)
{
	if(e.Reason == GridResizeCellsReason.HitTest)
	{
		int row, col;
		if(this.gridDataBoundGrid1.PointToRowCol(e.Point, out row, out col)
			&& row != 1)
		{
			e.Cancel = true;
		}
	}
}


SS Stephane SansCartier May 24, 2005 06:21 PM UTC

Great! And how would I set a minimum size? I don’t want the user to hide the column header and not be able to see it (for some reason, when the user resizes the header to 0, he can not resize it to see it again).


AD Administrator Syncfusion Team May 24, 2005 06:32 PM UTC

You can handle ColWidthChanging and cancel the changes if necessary. You would also want to handle ColumnsHiding to prevent the user from hiding the column by sizing it to zero (if you want to avoid this).
 
private void gridControl1_ColWidthsChanging(object sender, GridRowColSizeChangingEventArgs e)
{
        if(e.From == 2 && e.Values[0] > 200 || e.Values[0] < 50)
              e.Cancel = true;
}
Here is a sample.


SS Stephane SansCartier May 24, 2005 07:09 PM UTC

Everything is working, thank!

Loader.
Live Chat Icon For mobile
Up arrow icon