从DataGrid ItemSource获取值作为ObservableCollection吗? [英] Get values from DataGrid ItemSource as ObservableCollection?

查看:94
本文介绍了从DataGrid ItemSource获取值作为ObservableCollection吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

  我怎样才能从DataGrid获得值作为ObservableCollection?

    how can i get values from DataGrid as ObservableCollection?

public ObservableCollection< PersonBO> Fetch()

public ObservableCollection<PersonBO> Fetch()

{

}

在这里我加载了DataGrid1.ItemSource = Fetch();

here i loaded DataGrid1.ItemSource= Fetch();

具有两列的DataGrid.加载时间根据第一列"对记录进行排序.此DataGrid也具有AutoSortingColumns = True.

the DataGrid having two columns. Loaded time the records sorting based on First column. also this DataGrid having AutoSortingColumns=True..

如果我基于第二列进行了排序,则记录位置已更改(因为基于第二列进行了排序).

if i sort based on Second column the record Positions are Changed(Because sorting based on Second Column)..

现在我希望将此DataGrid ItemSource用作ObservableCollection.

Now i want this DataGrid ItemSource as ObservableCollection..

我的代码:

ObservableCollection< PersonBO> source = DataGrid1.ItemSource作为ObservableCollection< PersonBO> ;;

ObservableCollection<PersonBO> source=DataGrid1.ItemSource as ObservableCollection<PersonBO>;

但是在这里,我仅获得我的原始值(它基于Firstcolumn排序.这仅是我加载的值).

but here i am getting my original value only(its sorted based on Firstcolumn. this only i loaded).

我希望将DataGrid项源作为具有行顺序的ObservableCollection(基于对secondColumn进行排序后的结果)?

i want the DataGrid itemsource as ObservableCollection with row order(based on after sorting secondColumn)?

有人建议吗?

推荐答案

其他人可能会纠正我,但我不会相信您可以做自己想做的事而无需实际对Fetch()返回的集合进行排序.

Others may correct me, but I don't believe you can do what you want without actually sorting the collection returned by Fetch() yourself.

 

我不习惯使用MS DataGrid,但如果它能像Xceed DataGrid一样工作,则DataGrid.Items将按排序顺序进行,尽管不是ObservableCollection< T>

I'm not used to using the MS DataGrid, but if it works anything like the Xceed DataGrid, DataGrid.Items will be in sorted order, though not an ObservableCollection<T>


这篇关于从DataGrid ItemSource获取值作为ObservableCollection吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆