Page 2 of 2

Re: Sorting by column in a datagridview

Posted: Wed Sep 18, 2019 4:59 pm
by mtartaglia
$currentsort ended up being null in the debugger. I set it when someone sorts a column.

Obviously I am missing something. Sorry to ask this, but I am hoping you can be a little more specific as to where your two suggestions should be put.

Re: Sorting by column in a datagridview

Posted: Wed Sep 18, 2019 5:15 pm
by jvierra
If you would just add a DataTable and leave everything else alone my code would work as intended. It is clear that you method of creating and loading the table is not correct for proper functioning of the sort capability.
All sorting in a grid is one automatically without any code. The Sort filter gets set whenever a column is clicked. It will only be null on the initial load so you need to check and set the sort to some initial state.

Re: Sorting by column in a datagridview

Posted: Wed Sep 18, 2019 5:18 pm
by jvierra
Also no`te that the code I posted is intended only to be used when you refresh the data, It will not work as expected if you use it in multiple events. You should have NO events managing the sort or column clicks as they will just create issues.