Customized sorting on DataTable in C#?
Posted
by Steve
on Stack Overflow
See other posts from Stack Overflow
or by Steve
Published on 2010-01-22T04:09:03Z
Indexed on
2010/03/31
11:03 UTC
Read the original article
Hit count: 401
This is a C# Winform question. I have a DataGridView which is bounded to a DataTable. I construct the DataTable myself, which several DataColumn instances. When the DataTable is bound to the DataGridView, by default, every column is sortable by clicking the headers of the DataGridView.
But the sorting behavior is something "by default". It seems that it is sorted by string. This is true even if I put this as my code:
DataColumn dc = new DataColumn("MyObjectColumn", typeof(MyObject));
And MyObject has overriden ToString() and has implemented the IComparable interface. That means even if I have told the DataTable how to sort the special column with the implementation of IComparable interface, DataGridView still doesn't do it the way I expect.
So how can I let DataTable sort data in the way I want?
Thanks for the answers.
© Stack Overflow or respective owner