views:

6269

answers:

4

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?

+1  A: 

Do you have to call the DataGridView.DataBind() method?

I'm so used to ASP.NET that I forget the WinForms stuff.

TheTXI
A: 

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.

Andrew Backer
+2  A: 

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?

BFree
Answer is that it works fine - I did something stupid. Too bad I can't have all of you looking over my shoulder.
ScottStonehouse
:) Thanks for accepting the answer, although it wasn't much of an answer. I figured it had to be some simple oversight.
BFree
A: 

Here some useful datagridview tips:

http://vb.net-informations.com/datagridview/vb.net_datagridview_tutorial.htm

GeverUK