DataGridView, BindingSource and sorting in vb.net
-
05-07-2019 - |
Question
I am emulating the functionality of an old app in VB.Net. I have a DataGridView on my form which is bound to a BindingSource. I have a button on the toolbar which lanuches a sort dialog. The sort dialog allows sorting by up to 3 columns.
So I'm building a string from the results of the dialog and setting the BindingSource.Sort property with it. But this doesn't update my DataGridView. Am I missing a step - do I need to tell something to refresh?
Solution
I just tried this with a simple test app, and it sorted without having to call any refresh. Can you post some code? Are you sure you're building up the Sort string correctly?
OTHER TIPS
Do you have to call the DataGridView.DataBind() method?
I'm so used to ASP.NET that I forget the WinForms stuff.
What is the underlying object, and does it support sorting? You can check via the .SupportsSorting property (iirc). If it is a DataTable then you should be ok.
Have you tried applying the sort directly to the Grid?
You can try calling BindingSource.ResetBindings(false) after you update the sort property, just to be safe, but you shouldn't have to.