16 May

There are several ways to sort data in C# but one of the easiest ways is using BindingSource sort capability.
Depending on what object (underlying list) is linked to the BindingSource as its DataSource and whether it has implemented IBindingList or IBindingListView interfaces or not, you can use this feature.

To find out whether a BindingSource with current DataSource supports sorting, use ‘SupportsSorting’ property:

if (bindingSource1.SupportsSorting)
	bindingSource1.Sort = "Code, Name";

Similarly, you can benefit from BindingSource.Filter .

One Response to “Sorting”

  1. Adeel February 13, 2014 at 1:51 pm #

    This looks a very simple and concise way to sort the data source before binding it to any control.It is a way better approach as compared to the custom data source sorting as it requires some markup and events handling.I needed something like that

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: