当一个可枚举的对象绑定到它时,我的datagridview不排序 [英] my datagridview does not sort when an ienumrable object bind to it
本文介绍了当一个可枚举的对象绑定到它时,我的datagridview不排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个大问题.当我将IEnumrable对象绑定到winForm中的datagridview时,无法通过单击列标题对其进行排序.但是当我绑定一个DataTable对象时,可以对其进行排序吗?
如何在不将IEnumrable对象转换为数据表的情况下解决此问题?
非常感谢.
I have a big problem. When i bind a IEnumrable object to datagridview in winForm, I can not sort it by clicking on column header . But when I bind a DataTable object, I can sort it ?
How can I solve this problem without converting my IEnumrable object to datatable ??
Thanks a lot.
推荐答案
我不知道为什么,但这是事实:如果使用List作为DataGridView的数据源,则排序被禁用-我怀疑这与IListSource有关,但我不知道.
您可以只为DataGridView将IEnumerable转换为DataTable,这里有一个技巧,提供了一种简单的方法: ^ ]
I don''t know why, but it is true: if you use a List as the DataSource of the DataGridView, sorting is disabled - I suspect it is something to do with IListSource but I don''t know.
You could convert your IEnumerable to a DataTable just for the DataGridView, there is a Tip here which provides a simple method: Converting a List to a DataTable[^]
这篇关于当一个可枚举的对象绑定到它时,我的datagridview不排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文