views:

1710

answers:

4

Hi all,

How do I sort the columns in a winforms datagrid control into alphabetical order?

Thanks

A: 

Sorry forgot to mention this is a windows form project.

+1  A: 

Have you tried binding the DataGrid to a DataTable object (instead of a view) and turning setting the "AllowSorting" property to true on the DataGrid? I believe the grid will then automatically sort the table source for you.

If not, you can always catch the event when a column header is clicked and rebuild a DataView to bind to the DataGrid.

Dillie-O
+1  A: 

This MSDN article should guide you along the way.

If you provide more information perhaps we can provide actual code for your specific problem.

Esteban Brenes
A: 

Scott, can you clarify - you want to sort the columns in alphabetical order, or allow sorting on columns?

GalacticCowboy