DataGridView sorts by clicking column header. How to prevent it.

I don't want the user to sort the column.  I want him/her to be able to resize the columns, but not sort by clicking.

I'm certain this will be very simple, but I've been up and down the properties box and I can't find anything that changes this behavior.

Who is Participating?
Column has SortMode. Set it to NotSortable.
cestes002Author Commented:
Columns are set at runtime by .NET.  When the form activates, the table is read and the DGV is populated.  At design time, I have no idea what the columns' names will be.

On the strength of your suggestion, I found the following works just fine.

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

Thanks.  Now, how do I mark this as solved?  It's been years since I've been on EE.
cestes002Author Commented:
NM - I found the button
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.