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

column resize

tried the code for preventing column resize and it does not work.still able to grab the column in the column header and resize the datagrid. am i missing something? 5.44 How can I prevent my user from sizing columns in my datagrid? You can do this by subclassing your grid and overriding OnMouseMove, and not calling the baseclass if the point is on the columnsizing border. [C#] public class MyDataGrid : DataGrid { protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e) { DataGrid.HitTestInfo hti = this.HitTest(new Point(e.X, e.Y)); if(hti.Type == DataGrid.HitTestType.ColumnResize) { return; //no baseclass call } base.OnMouseMove(e); } }

2 Replies

JO john May 11, 2004 04:15 AM

Just in case anybody else has this problem, it seems you also have to do the same test mentioned here in OnMouseDown, or the user will still be able to grab and move the divider between columns.


AD Administrator Syncfusion Team December 22, 2005 02:22 AM

Hi pls try this method also.I added a event handler to the DataGridColumnStyle.WidthChanged. and reset the width to prefered value. refer the attached sample for more details >tried the code for preventing column resize and it does not work.still able to grab the column in the column header and resize the datagrid. >am i missing something? > >5.44 How can I prevent my user from sizing columns in my datagrid? > >You can do this by subclassing your grid and overriding OnMouseMove, and not calling the baseclass if the point is on the columnsizing border. > >[C#] > >public class MyDataGrid : DataGrid > >{ > > protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e) > > { > > DataGrid.HitTestInfo hti = this.HitTest(new Point(e.X, e.Y)); > > if(hti.Type == DataGrid.HitTestType.ColumnResize) > > { > > return; //no baseclass call > > } > > base.OnMouseMove(e); > > } > >} > > >

datagrid3.zip

Loader.
Live Chat Icon For mobile
Up arrow icon