It seems that you do not support the correct execution order. The code you wrote will do the job
dgvConnections.Columns[e.ColumnIndex].SortMode = DataGridViewColumnSortMode.NotSortable;
but make sure you call it after initializing the DataGridView.
If you want to use it for specific columns, as you mentioned in your question, you need to find the index and set sortmode.
source share