How to prevent sorting in datagriview
I have a datagridview named "dgvStudents" and DO NOT want user to click the heading to sort it.
I found the following code but don't know how to incorporate in my code. Can someone please help ?
Public Class CustomDataGrid
Inherits DataGrid
Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
Dim point As New Point(e.X, e.Y)
Dim hti As DataGrid.HitTestInfo = HitTest(point)
' don't sort column 1
If hti.Type = HitTestType.ColumnHeader AndAlso hti.Column = 1 Then
Return
End If
MyBase.OnMouseDown(e)
End Sub
End Class
Re: How to prevent sorting in datagriview
I think you should be able to just set the SortMode property of each column to NotSortable.
Re: How to prevent sorting in datagriview
Note that the code you posted is NOT for the DataGridView at all:
Quote:
Public Class CustomDataGrid
Inherits DataGrid
Different beast altogether.