c# - Difference between DataView.Sort and DataTable.OrderBy().AsDataView()? -
i have datagridview bound datatable contains column of custom types need sort by. custom type (mycustomtype) implements icomparable<mycustomtype> how wanted sorting work.
i tried 2 methods create dataview use grid's data source:
mydatatable dt = new mydatatable(); dataview dv = new dataview(dt); dv.sort = "mycustomfield"; this did not work - "almost" worked, rows not sorted correctly.
second method:
mydatatable dt = new mydatatable(); dataview dv = dt.orderby(row => row.mycustomfield).asdataview(); this seems doing want. question is, what's difference between these 2 methods? possible dataview.sort not using icomparable<t> implementation, , linq-enabled dataview is? why case?
furthermore, know relative performance of non-linq-enabled , linq-enabled dataviews? seems if there isn't huge performance hit, there's no longer reason use non-linq-enabled version.
when call .sort on dataview, sorts particular instance of object. second method creates brand new object , assigns dv variable. can critical difference.
edit: not second method specifically, since you're not assigning, re-assigning. if had existing dataview, re-assigned using orderby method, you'd have scenario suggested.
sorry, wasn't clear should have been.
Comments
Post a Comment