$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.
Sorting by column in a datagridview
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
- mtartaglia
- Posts: 101
- Last visit: Mon Dec 19, 2022 11:45 am
Re: Sorting by column in a datagridview
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.
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
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.