How to cancel sorting of DataGridView?

UncleRonin

Well-known member
Joined
Feb 28, 2006
Messages
230
Location
South Africa
Programming Experience
5-10
Okay, I'm using a DGView to display Decimal values, but I don't want to allow the user to sort the DGV (When the column header is clicked). How can I cancel the sorting that occurs? Is there an event that can be caught that will prevent the sorting, or a property that must be set... this sorting is causing me all kinds of grief!
 
Although not the exact solution you have led me to the solution! First I tried messing around with the SortCompare event, then did deeper searching through the MSDN and Voila! I know feel like an arse!

Column.SortMode = DataGridViewColumnSortMode.NotSortable

That, ladies and gentlemen, is the solution. It is accessible through the DGview.columns property and then when you select a column its right there for you to promptly disable sorting and forever live happily ever after. To think that on the internet there was no solution to this problem... what the hell...
 
Or you can right-click on the Datagridview, go to Edit Columns. For each column, under the SortMode property, change to NotSortable.
 
Back
Top