tags:

views:

25

answers:

0

I have a DataGridView which is bound to a DataTable that contains a column of custom types that I need to sort by. This custom type (MyCustomType) implements IComparable<MyCustomType> which is how I wanted the sorting to work.

I tried 2 methods to create a DataView which I would use as the grid's data source:

MyDataTable dt = new MyDataTable();
DataView dv = new DataView(dt);
dv.Sort = "MyCustomField";

This did not really work properly - it "almost" worked, but sometimes my rows would not be sorted correctly.

Second method:

MyDataTable dt = new MyDataTable();
DataView dv = dt.OrderBy(row => row.MyCustomField).AsDataView();

This seems to be doing what I want. My question is, what's the difference between these two methods? Is it possible that DataView.Sort is not using my IComparable<T> implementation, and the LINQ-enabled DataView is? Why would that be the case?

Furthermore, does anyone know about the relative performance of non-LINQ-enabled and LINQ-enabled DataViews? It seems like if there isn't a huge performance hit, there's no longer any reason to use the non-LINQ-enabled version.