In winforms .Net Framework 1.1, is there any way to disable sorting on specific column in datagrid.
If I try to set Allow sorting equal to false, then it disable sorting in all columns. But I need to disable specific columns in the datagrid.
this.dataGrid1.AllowSorting = false;
DataGrid control doesn't have a property to control sorting of columns separately. You can just allow or disallow sorting of all columns by setting
AllowSorting.But looking into source code of the control, the control performs sorting by handling mouse up, by hit-testing to check if the mouse up if happening on column header. So to customize the behavior, you can override
OnMouseUpand fool the base method by passing a fake mouse event args:Then you can use
MyDataGridcontrol on form:You can enhance the code example and add a property to contain a list of sortable or non-sortable properties and instead of
hti.Column == 0check for those sortable/non-sortable column indices.