Question DataGridView prevent sort

Misko

Member
Joined
Jan 5, 2009
Messages
9
Programming Experience
Beginner
I have a DataGridView in which I display data from SQLDataTable. My DataGridView has two columns (‘ID’, ‘Name’) and multiple rows. When the user clicks on the column header, he can change the order in which data is displayed (ascending, descending).
What can I do to unable the user to change data order?
Thanks!
 
Click the the Smart-Tag for the DataGridView and then Edit Columns. Set the Sort Mode for the columns to Not Sortable.

You can do it from code as well.

VB.NET:
	Private Sub DataGridView1_Sorted(ByVal sender As System.Object, ByVal e As System.EventArgs) _
	Handles DataGridView1.Sorted

		For i As Integer = 0 To Me.DataGridView1.Columns.Count - 1
			Me.DataGridView1.Columns(i).SortMode = DataGridViewColumnSortMode.NotSortable
		Next

	End Sub
 

Latest posts

Back
Top