Sorting a BindinSource

Sorting a BindinSource

Anonymous
Not applicable
524 Views
1 Reply
Message 1 of 2

Sorting a BindinSource

Anonymous
Not applicable

Hello all.  I was wondering if anyone could help me with sorting a bindingsource.  In the Revit SDK samples, there is project called LevelsProperty.  It has a datagridview linked to bindingsource1 that gets filled with Revit Level information.  I would like to keep the datagridview sorted by "Elevation" but I can't figure out how to do this.  By reading online, the bindingsource should be able to be sorted by using the line below but this doesn't seem to do anything.

 

bindingSource1.Sort = "Elevation DESC";  // doesn't work and does not produce an error

 

Any ideas?

 

 

0 Likes
Accepted solutions (1)
525 Views
1 Reply
Reply (1)
Message 2 of 2

jeremytammik
Autodesk
Autodesk
Accepted solution

Dear Jdean,

 

Thank you for your query.

 

This is not really a Revit API query, of course.

 

It is a pure .NET issue.

 

Have you read the Microsoft documentation on the BindingSource.Sort property?

http://msdn.microsoft.com/en-us/library/system.windows.forms.bindingsource.sort(v=vs.110).aspx

 

It specifies a pre-requisite: "To support sorting, the underlying list must implement the IBindingList or IBindingListView interfaces. This capability can be queried through the SupportsSorting property."

 

Is this pre-requisite fulfilled in your case?

 

That documentation also provides a simple sample.

 

It should be possible for you to adapt your code to make use of the approach demonstrated there, possibly by piping your data through a temporary container of some sort.

 

My built-in parameter checker demonstrates sorting in a Revit add-in, if I am not mistaken:

 

 

I hope this helps.

 

Best regards,



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes